From patchwork Thu Apr 28 13:20:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 66900 Delivered-To: patch@linaro.org Received: by 10.140.93.198 with SMTP id d64csp212285qge; Thu, 28 Apr 2016 06:20:48 -0700 (PDT) X-Received: by 10.66.156.232 with SMTP id wh8mr20424477pab.153.1461849648236; Thu, 28 Apr 2016 06:20:48 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id sj6si1315804pac.205.2016.04.28.06.20.47; Thu, 28 Apr 2016 06:20:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-samsung-soc-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-samsung-soc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-samsung-soc-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751986AbcD1NUq (ORCPT + 4 others); Thu, 28 Apr 2016 09:20:46 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:50278 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751829AbcD1NUp (ORCPT ); Thu, 28 Apr 2016 09:20:45 -0400 Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout1.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0O6C00D7TIEIJ710@mailout1.w1.samsung.com>; Thu, 28 Apr 2016 14:20:42 +0100 (BST) X-AuditID: cbfec7f4-f796c6d000001486-7c-57220e2a23bd Received: from eusync3.samsung.com ( [203.254.199.213]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id 8C.6D.05254.A2E02275; Thu, 28 Apr 2016 14:20:42 +0100 (BST) Received: from amdc1339.digital.local ([106.116.147.30]) by eusync3.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0O6C00CBKIEFYJ30@eusync3.samsung.com>; Thu, 28 Apr 2016 14:20:42 +0100 (BST) From: Marek Szyprowski To: linux-media@vger.kernel.org, linux-samsung-soc@vger.kernel.org Cc: Marek Szyprowski , Sylwester Nawrocki , Laurent Pinchart , Krzysztof Kozlowski , Bartlomiej Zolnierkiewicz , Hans Verkuil Subject: [PATCH v2] media: vb2-dma-contig: configure DMA max segment size properly Date: Thu, 28 Apr 2016 15:20:03 +0200 Message-id: <1461849603-6313-1-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.2 In-reply-to: <57220299.3000807@xs4all.nl> References: <57220299.3000807@xs4all.nl> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprCLMWRmVeSWpSXmKPExsVy+t/xq7pafErhBo/vs1tsnLGe1WLJz11M Fq9fGFp0TlzCbtGzYSurxYzz+5gs1h65y25x+E07qwOHx5TfG1k9ZnfMZPXo27KK0ePzJrkA ligum5TUnMyy1CJ9uwSujEctP5gK3shXnH+1hLWBcZ5UFyMnh4SAicTO+ddZIWwxiQv31rN1 MXJxCAksZZQ43riTFcJpYpI4f/ouC0gVm4ChRNfbLjYQW0TASWLhrL/sIEXMAiuYJN7OvQSW EBYIkdj56BnYWBYBVYneX3vB4rwC7hJr9h5ggVgnJ/H/5QomEJtTQFPietMisLiQgIbEnzk3 2Scw8i5gZFjFKJpamlxQnJSea6hXnJhbXJqXrpecn7uJERJWX3YwLj5mdYhRgINRiYd3UoJi uBBrYllxZe4hRgkOZiUR3vs8SuFCvCmJlVWpRfnxRaU5qcWHGKU5WJTEeefueh8iJJCeWJKa nZpakFoEk2Xi4JRqYFzBMa3eOD+pfOGGgnCtYumqBUfXznp478N9j8agqSezLT2Zz1tHzDt8 5+D/4KsNHB6nC6PS1wm83Xp4KXvFovmHc39N5tORnr91vVX8+Y9/210da7/ezZo336Tdf9nC h1d99Y8I3Le5YWZp7tLe9bf5RamYL//B8uc3NAoiz77xN79S1vKqs06JpTgj0VCLuag4EQBH hBwcJwIAAA== Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org This patch lets vb2-dma-contig memory allocator to configure DMA max segment size properly for the client device. Setting it is needed to let DMA-mapping subsystem to create a single, contiguous mapping in DMA address space. This is essential for all devices, which use dma-contig videobuf2 memory allocator and shared buffers (in USERPTR or DMAbuf modes of operations). Signed-off-by: Marek Szyprowski --- Hello, This patch is a follow-up of my previous attempts to let Exynos multimedia devices to work properly with shared buffers when IOMMU is enabled: 1. https://www.mail-archive.com/linux-media@vger.kernel.org/msg96946.html 2. http://thread.gmane.org/gmane.linux.drivers.video-input-infrastructure/97316 3. https://patchwork.linuxtv.org/patch/30870/ As sugested by Hans, configuring DMA max segment size should be done by videobuf2-dma-contig module instead of requiring all device drivers to do it on their own. Here is some backgroud why this is done in videobuf2-dc not in the respective generic bus code: http://lists.infradead.org/pipermail/linux-arm-kernel/2014-November/305913.html Best regards, Marek Szyprowski changelog: v2: - fixes typos and other language issues in the comments v1: http://article.gmane.org/gmane.linux.kernel.samsung-soc/53690 --- drivers/media/v4l2-core/videobuf2-dma-contig.c | 39 ++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) -- 1.9.2 -- To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/media/v4l2-core/videobuf2-dma-contig.c b/drivers/media/v4l2-core/videobuf2-dma-contig.c index 461ae55eaa98..d0382d62954d 100644 --- a/drivers/media/v4l2-core/videobuf2-dma-contig.c +++ b/drivers/media/v4l2-core/videobuf2-dma-contig.c @@ -443,6 +443,36 @@ static void vb2_dc_put_userptr(void *buf_priv) } /* + * To allow mapping the scatter-list into a single chunk in the DMA + * address space, the device is required to have the DMA max segment + * size parameter set to a value larger than the buffer size. Otherwise, + * the DMA-mapping subsystem will split the mapping into max segment + * size chunks. This function increases the DMA max segment size + * parameter to let DMA-mapping map a buffer as a single chunk in DMA + * address space. + * This code assumes that the DMA-mapping subsystem will merge all + * scatter-list segments if this is really possible (for example when + * an IOMMU is available and enabled). + * Ideally, this parameter should be set by the generic bus code, but it + * is left with the default 64KiB value due to historical litmiations in + * other subsystems (like limited USB host drivers) and there no good + * place to set it to the proper value. It is done here to avoid fixing + * all the vb2-dc client drivers. + */ +static int vb2_dc_set_max_seg_size(struct device *dev, unsigned int size) +{ + if (!dev->dma_parms) { + dev->dma_parms = kzalloc(sizeof(dev->dma_parms), GFP_KERNEL); + if (!dev->dma_parms) + return -ENOMEM; + } + if (dma_get_max_seg_size(dev) < size) + return dma_set_max_seg_size(dev, size); + + return 0; +} + +/* * For some kind of reserved memory there might be no struct page available, * so all that can be done to support such 'pages' is to try to convert * pfn to dma address or at the last resort just assume that @@ -499,6 +529,10 @@ static void *vb2_dc_get_userptr(struct device *dev, unsigned long vaddr, return ERR_PTR(-EINVAL); } + ret = vb2_dc_set_max_seg_size(dev, PAGE_ALIGN(size + PAGE_SIZE)); + if (!ret) + return ERR_PTR(ret); + buf = kzalloc(sizeof *buf, GFP_KERNEL); if (!buf) return ERR_PTR(-ENOMEM); @@ -675,10 +709,15 @@ static void *vb2_dc_attach_dmabuf(struct device *dev, struct dma_buf *dbuf, { struct vb2_dc_buf *buf; struct dma_buf_attachment *dba; + int ret; if (dbuf->size < size) return ERR_PTR(-EFAULT); + ret = vb2_dc_set_max_seg_size(dev, PAGE_ALIGN(size)); + if (!ret) + return ERR_PTR(ret); + buf = kzalloc(sizeof(*buf), GFP_KERNEL); if (!buf) return ERR_PTR(-ENOMEM);