From patchwork Mon Aug 14 08:41:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanimir Varbanov X-Patchwork-Id: 109962 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp4058494qge; Mon, 14 Aug 2017 01:42:28 -0700 (PDT) X-Received: by 10.99.6.74 with SMTP id 71mr21743416pgg.328.1502700148448; Mon, 14 Aug 2017 01:42:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1502700148; cv=none; d=google.com; s=arc-20160816; b=kxspDl8qg99vnjT5IepsrTY+qBV+qng+rIXtrLFuI+VseeJ/1KG2cqUFQbJ5lU0iuZ nLeVtiKze2ZIOmPTmfhItuPzBoRIKDLNHg2mytlTkZ4QEUJ4VA1X2/ny7jogsneGxDvg yx5AWxys456pPfoftHBjFCtygp03kuuZ8aBZ9A4KUnEM7ujsqnHNgz/qnB/TECvpL++W Je34VYfLTJ5sGelGcFAWEibIE646kgGxilhfHBsWOJtguea4TSR3sO8Jas9BhhVbhHVR jThZp/N0x0u0kRf+0aJElpVu88VlSrvxcYU5V8vaE5skRs2xBveFwiqrBCdEAOS5bfPV ujAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=ogoscxpFRIZqpmBYCIazZ9zQE+TlAsk7zglrDeuCoug=; b=CXLuILb/jjtuQXnqUnuxACnim8HG2qiNFBqzt++R8bGyLWlOVSSrdQ6W60qRNsnCLc BAcjeP9y22CydU8EgCK0/V/XrU40+KOz//gmCjQgpVguoVhcfCm9lVzZuxtWkIATtoO3 1ix1NlXVlokHtp4Eo3ZeEp+59u7uMETYoA3kU9F8Xk3gUSZRLdPgVwDDJzXvxUBNjbwO dNDjh9a1Adaad9UaoPBtqraMyClO7dkwAPjYtAYw+sbONDa7DlNctEWaYBTtTd+GOv5t wSuJrRtIqkIQrn7uqQd5Kedg4545dudMS4sDGnykM+QjSLStqooc3jKr0YGJeSc9rbIB Aq7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QM+Foq5b; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r9si4378743plj.462.2017.08.14.01.42.28; Mon, 14 Aug 2017 01:42:28 -0700 (PDT) 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; dkim=pass header.i=@linaro.org header.s=google header.b=QM+Foq5b; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752573AbdHNImM (ORCPT + 25 others); Mon, 14 Aug 2017 04:42:12 -0400 Received: from mail-wr0-f181.google.com ([209.85.128.181]:32918 "EHLO mail-wr0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752199AbdHNImK (ORCPT ); Mon, 14 Aug 2017 04:42:10 -0400 Received: by mail-wr0-f181.google.com with SMTP id b65so7526229wrd.0 for ; Mon, 14 Aug 2017 01:42:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=ogoscxpFRIZqpmBYCIazZ9zQE+TlAsk7zglrDeuCoug=; b=QM+Foq5b/KyVqR66noHb8/Sf3VmHzHEJTdTN8MiXwXz88Ip2DF1jlSie5a9nscVfOp fvFYfolfqRZJQkXFv8jPyKvspOrq7stYnIBq+UjaIHBnXHpLZ4A5gIDVZqunmCqbbTuH 9T7pAnCck4wn3w1la+YoJ1+Rr3me1MLZ5yLPI= 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; bh=ogoscxpFRIZqpmBYCIazZ9zQE+TlAsk7zglrDeuCoug=; b=ib6LMUIEF/dv5wlbAoQk+jrcI7DpjVKvAdpBEswYy4TWlWZPQZLrfq8crM79cQGW19 DTla1HVzW8AXRp/8OzUgCOehVqMk3TLnxgTzdGqcehSVOOjdRNWndhwx4+0qymnB03cL 1bU50kdNBQLumY+xalyUcG3RQ78FkO4LbXzde8HMmIjXbuMhAl1dBOnP10C3xjBRkLZJ pYiurMuNBMdOt3T8+4W+hWEVqPxi4bbXW1w5keTiTe21omI6Q0tqtbuRqv8acbdm9H/b 5NdDQZC/U07bMj9pvQ4mjUQTepeguSr1ZixbmgXTflkmANN8us/mGHa1FTDXkbJ4qZxH dr6w== X-Gm-Message-State: AHYfb5jkKUrSpi6WhWiMeI+FokvONe4N/qY9TwHjvALCnyJaxEvXFE9D SI0yJ6D6nIMh6Cfc X-Received: by 10.223.133.228 with SMTP id 33mr14953759wru.211.1502700129427; Mon, 14 Aug 2017 01:42:09 -0700 (PDT) Received: from localhost.localdomain ([37.157.136.206]) by smtp.gmail.com with ESMTPSA id f47sm7238535wrf.78.2017.08.14.01.42.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Aug 2017 01:42:08 -0700 (PDT) From: Stanimir Varbanov To: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org Cc: Mauro Carvalho Chehab , Hans Verkuil , Pawel Osciak , Marek Szyprowski , Kyungmin Park , Sakari Ailus , Laurent Pinchart , Stanimir Varbanov Subject: [RFC PATCH] media: vb2: add bidirectional flag in vb2_queue Date: Mon, 14 Aug 2017 11:41:55 +0300 Message-Id: <20170814084155.10770-1-stanimir.varbanov@linaro.org> X-Mailer: git-send-email 2.11.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, This RFC patch is intended to give to the drivers a choice to change the default behavior of the v4l2-core DMA mapping direction from DMA_TO/FROM_DEVICE (depending on the buffer type CAPTURE or OUTPUT) to DMA_BIDIRECTIONAL during queue_init time. Initially the issue with DMA mapping direction has been found in Venus encoder driver where the firmware side of the driver adds few lines padding on bottom of the image buffer, and the consequence was triggering of IOMMU protection faults. Probably other drivers could also has a benefit of this feature (hint) in the future. Signed-off-by: Stanimir Varbanov --- drivers/media/v4l2-core/videobuf2-core.c | 3 +++ include/media/videobuf2-core.h | 11 +++++++++++ 2 files changed, 14 insertions(+) -- 2.11.0 Acked-by: Sakari Ailus diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c index 14f83cecfa92..17d07fda4cdc 100644 --- a/drivers/media/v4l2-core/videobuf2-core.c +++ b/drivers/media/v4l2-core/videobuf2-core.c @@ -200,6 +200,9 @@ static int __vb2_buf_mem_alloc(struct vb2_buffer *vb) int plane; int ret = -ENOMEM; + if (q->bidirectional) + dma_dir = DMA_BIDIRECTIONAL; + /* * Allocate memory for all planes in this buffer * NOTE: mmapped areas should be page aligned diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h index cb97c224be73..0b6e88e1aa79 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -427,6 +427,16 @@ struct vb2_buf_ops { * @dev: device to use for the default allocation context if the driver * doesn't fill in the @alloc_devs array. * @dma_attrs: DMA attributes to use for the DMA. + * @bidirectional: when this flag is set the DMA direction for the buffers of + * this queue will be overridden with DMA_BIDIRECTIONAL direction. + * This is useful in cases where the hardware (firmware) writes to + * a buffer which is mapped as read (DMA_TO_DEVICE), or reads from + * buffer which is mapped for write (DMA_FROM_DEVICE) in order + * to satisfy some internal hardware restrictions or adds a padding + * needed by the processing algorithm. In case the DMA mapping is + * not bidirectional but the hardware (firmware) trying to access + * the buffer (in the opposite direction) this could lead to an + * IOMMU protection faults. * @fileio_read_once: report EOF after reading the first buffer * @fileio_write_immediately: queue buffer after each write() call * @allow_zero_bytesused: allow bytesused == 0 to be passed to the driver @@ -495,6 +505,7 @@ struct vb2_queue { unsigned int io_modes; struct device *dev; unsigned long dma_attrs; + unsigned bidirectional:1; unsigned fileio_read_once:1; unsigned fileio_write_immediately:1; unsigned allow_zero_bytesused:1;