Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp5782310imb; Fri, 8 Mar 2019 02:07:37 -0800 (PST) X-Google-Smtp-Source: APXvYqw0jGeGkz2g1vKuMkqwdFAKfO9/8LWYDLw55TqB7Ow+uewJ1sKTfmmb6Qsv8Gzx/V/j8BTQ X-Received: by 2002:a63:b242:: with SMTP id t2mr15956837pgo.451.1552039657608; Fri, 08 Mar 2019 02:07:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1552039657; cv=none; d=google.com; s=arc-20160816; b=GlplAVEVukvnseLVE4d8sRLz6OwwOjhgeu/yS5GQEnsx5zkvlLMV7JIGRI4uhJhzDt hX+GpoQP0+IT9bd8nhKV9pv+W27tdmHrxX7gdIzjksWRPT7hO6kbBi/CccC6v4LcvFuE esiK6Og/yPeboKxes2Azfw9e1e5kx7l22TgpBOT8i2ayIGQi03z/r0C4asF7EnOQj8s2 OR2t9+3fqfRzKS0lTuykTMyqU5JStFGYx+OoVY5KF+HggKrqszQKQFch8pSq5claU90d mtxfqjX/yFDWwY0U3A0bu6P4zTQQ2ZHeMceHsWuDuXNSpiEzgn25eA6REepBmuvsOOwF aakA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=EEUdSmxADmMRVW2KhcZu4aYDw/MXK7gceVLR6XLNiTE=; b=gpNMbBwji0dNenfLRCXH1Qge5kmz7RBN9GBZYggNzlzKEuBWvYITaQFtU+Mejv4evl DxsP4JNeipR8wzLycKD1CodoECL0+1ja/WsJUUNgc1/vr67+6HXtoO5LgSbRRnziZEzc BlDN2TBre7Gx1UT1yzWiP0dfeZY9DUfuiKWhHFizFKkm55OEjY63bf2Iq7BYJlCv/Z/P 9C3ldTEtdCaAeJfPFK5nDDtKocMa5geKAMd+rDQmrGRjOAIHVu6lQUPz6C3gQ//kKAic rGSLOX6G0OzY4qcDYb/sJZNsNTONhjbc1oOq/HYXs/XEFB5kPfU+apq/epbym8FGaOos VzQw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q207si6039775pgq.321.2019.03.08.02.07.21; Fri, 08 Mar 2019 02:07:37 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726361AbfCHKFE (ORCPT + 99 others); Fri, 8 Mar 2019 05:05:04 -0500 Received: from regular1.263xmail.com ([211.150.99.135]:53226 "EHLO regular1.263xmail.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725789AbfCHKFE (ORCPT ); Fri, 8 Mar 2019 05:05:04 -0500 Received: from randy.li?rock-chips.com (unknown [192.168.167.205]) by regular1.263xmail.com (Postfix) with ESMTP id 0CA6329E; Fri, 8 Mar 2019 18:04:51 +0800 (CST) X-263anti-spam: KSV:0; X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-KSVirus-check: 0 X-ABS-CHECKED: 4 Received: from randy-pc.lan (unknown [58.22.7.114]) by smtp.263.net (postfix) whith ESMTP id P4577T140460028839680S1552039482412209_; Fri, 08 Mar 2019 18:04:50 +0800 (CST) X-IP-DOMAINF: 1 X-UNIQUE-TAG: <3592bafda1430e3d55e003cbbd907b7a> X-RL-SENDER: randy.li@rock-chips.com X-SENDER: randy.li@rock-chips.com X-LOGIN-NAME: randy.li@rock-chips.com X-FST-TO: linux-media@vger.kernel.org X-SENDER-IP: 58.22.7.114 X-ATTACHMENT-NUM: 0 X-DNS-TYPE: 0 From: Randy Li To: linux-media@vger.kernel.org Cc: Randy Li , ayaka@soulik.info, joro@8bytes.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, pawel@osciak.com, m.szyprowski@samsung.com, kyungmin.park@samsung.com, mchehab@kernel.org, hverkuil@xs4all.nl, nicolas@ndufresne.ca, ezequiel@collabora.com, posciak@chromium.org, groeck@chromium.org, paul.kocialkowski@bootlin.com, linux-rockchip@lists.infradead.org Subject: [PATCH] [TEST]: media: vb2: reverse DMA addr of each plane Date: Fri, 8 Mar 2019 18:04:40 +0800 Message-Id: <20190308100440.14601-1-randy.li@rock-chips.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With the default iova and dma-iommu driver, the starting address of a new buffer would be at lower address than the previous one. This patch can solve this problem simply, but I want a way to control the address direction of the IOMMU/IOVA. The reason why we(ayaka and I) need to do this is simple, some devices want a contiguous memory for its pixel data. But with the single plane buffer, there is not a properly way to export its buffer offsets with the userspace, since their bytesperline and offset are not full related to the picture width or height. You can find more detail in the previous mail. Besides, this patch won't solve all the problem, if you don't disable the size_aligned of the iova driver or there would be a gap between the plane 0 and plane 1. This patch is used for showing the problem we met not for merging. Signed-off-by: Randy Li --- drivers/media/common/videobuf2/videobuf2-core.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index 15b6b9c0a2e4..6762d1547e49 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -204,11 +204,11 @@ static int __vb2_buf_mem_alloc(struct vb2_buffer *vb) * Allocate memory for all planes in this buffer * NOTE: mmapped areas should be page aligned */ - for (plane = 0; plane < vb->num_planes; ++plane) { - unsigned long size = PAGE_ALIGN(vb->planes[plane].length); + for (plane = vb->num_planes; plane > 0; --plane) { + unsigned long size = PAGE_ALIGN(vb->planes[plane - 1].length); mem_priv = call_ptr_memop(vb, alloc, - q->alloc_devs[plane] ? : q->dev, + q->alloc_devs[plane - 1] ? : q->dev, q->dma_attrs, size, q->dma_dir, q->gfp_flags); if (IS_ERR_OR_NULL(mem_priv)) { if (mem_priv) @@ -217,15 +217,15 @@ static int __vb2_buf_mem_alloc(struct vb2_buffer *vb) } /* Associate allocator private data with this plane */ - vb->planes[plane].mem_priv = mem_priv; + vb->planes[plane - 1].mem_priv = mem_priv; } return 0; free: /* Free already allocated memory if one of the allocations failed */ - for (; plane > 0; --plane) { - call_void_memop(vb, put, vb->planes[plane - 1].mem_priv); - vb->planes[plane - 1].mem_priv = NULL; + for (; plane < vb->num_planes; plane++) { + call_void_memop(vb, put, vb->planes[plane].mem_priv); + vb->planes[plane].mem_priv = NULL; } return ret; -- 2.20.1