From patchwork Thu Aug 30 17:20:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ezequiel Garcia X-Patchwork-Id: 10582397 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C32D8920 for ; Thu, 30 Aug 2018 17:23:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A9452288B7 for ; Thu, 30 Aug 2018 17:23:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A68AC289EB; Thu, 30 Aug 2018 17:23:01 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5176728E2F for ; Thu, 30 Aug 2018 17:23:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=Y5W+S2oXHRB/R623l3lqxaGYx+BNYPPFxaoUicgsvoU=; b=hylYTMJoBtbTifaSgHUCIisTZ5 5K2UJLg/8IbDylvGN7EvM7RvzVYUFye5Mhps6OtSCM7Xf1Qj7tOFhsZI0oH4Q80zGAs4pvIvhbH13 xHzaGx99sbLbPk++PAnOjRgUs6RUihfJGktDISZ7n6o1hCfmmrg34cncN5yFia/qGkvfZAIeyoCvo SVc70qzCE22f5EFEZNJYgmiy+9FFUfrnDZFQf9Ma+G2nd+iZTvyRqWasy8uBdFf8cW7NnBYhI4aIZ 4p6lwdnwu9UgknGzolKs7gC5S7d9WD+rsTIHwD37On+8zqpaPLKeAS8T8pM8K4RNtFOvl/heRU2Ul v/sO5oyA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fvQef-0007a8-PR; Thu, 30 Aug 2018 17:22:49 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fvQdI-0006vn-11 for linux-arm-kernel@bombadil.infradead.org; Thu, 30 Aug 2018 17:21:24 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=ZjmPZWA2tcZh7gubEUApBpckBhPqN6I1iAS9wy9JUBE=; b=RSddwaz4mFQYJ4tx4c7tj9Dm7 bYumGR5HezMvueIb2BOqw70RIrZbja7D12PtY7gkyH1JYulAyZwIbZVuT/fHTchmHdEY9z8HnMEm6 qcDFQHqYHpc+syjNqUcxcpM6SwrOsxrNHgyLu8nQW/Q3Qhz5GaNTBy3Sr3DTSSOHZHTsITJHKmz9T 37Ij7KI3RR4wZRlhYwGnoLKYlJErh18qTm9rFyKxDBnWCSTcgb1vPaOgV2TXpFuLOnYgzgf0Ym9qs 3dN+BNvC3W0aBaM+8GQdCN4E/aG6RAIeI0DXC55Q/B1M+6ivBhnKtYi56p6QMjvkvlSGhqA3zd2cz uJANaQMug==; Received: from bhuna.collabora.co.uk ([46.235.227.227]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fvQdE-00020m-Ve for linux-arm-kernel@lists.infradead.org; Thu, 30 Aug 2018 17:21:22 +0000 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: ezequiel) with ESMTPSA id BD5EB27D4B4 From: Ezequiel Garcia To: linux-media@vger.kernel.org, linux-usb@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC 1/3] HACK: ARM: dma-mapping: Get writeback memory for non-consistent mappings Date: Thu, 30 Aug 2018 14:20:28 -0300 Message-Id: <20180830172030.23344-2-ezequiel@collabora.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180830172030.23344-1-ezequiel@collabora.com> References: <20180830172030.23344-1-ezequiel@collabora.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180830_132121_118296_A4B8BCEF X-CRM114-Status: GOOD ( 10.28 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tomasz Figa , "Matwey V . Kornilov" , Keiichi Watanabe , Alan Stern , Laurent Pinchart , kernel@collabora.com, Ezequiel Garcia MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This is obviously a hack. Signed-off-by: Ezequiel Garcia --- arch/arm/include/asm/pgtable.h | 3 +++ arch/arm/mm/dma-mapping.c | 9 ++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h index a757401129f9..37ddd0d73434 100644 --- a/arch/arm/include/asm/pgtable.h +++ b/arch/arm/include/asm/pgtable.h @@ -122,6 +122,9 @@ extern pgprot_t pgprot_s2_device; #define pgprot_writecombine(prot) \ __pgprot_modify(prot, L_PTE_MT_MASK, L_PTE_MT_BUFFERABLE) +#define pgprot_writeback(prot) \ + __pgprot_modify(prot, L_PTE_MT_MASK, L_PTE_MT_WRITEBACK) + #define pgprot_stronglyordered(prot) \ __pgprot_modify(prot, L_PTE_MT_MASK, L_PTE_MT_UNCACHED) diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index 66566472c153..11cca7bbb0a8 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -633,9 +633,12 @@ static void __free_from_contiguous(struct device *dev, struct page *page, static inline pgprot_t __get_dma_pgprot(unsigned long attrs, pgprot_t prot) { - prot = (attrs & DMA_ATTR_WRITE_COMBINE) ? - pgprot_writecombine(prot) : - pgprot_dmacoherent(prot); + if (attrs & DMA_ATTR_WRITE_COMBINE) + prot = pgprot_writecombine(prot); + else if (attrs & DMA_ATTR_NON_CONSISTENT) + prot = pgprot_writeback(prot); + else + prot = pgprot_dmacoherent(prot); return prot; } From patchwork Thu Aug 30 17:20:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ezequiel Garcia X-Patchwork-Id: 10582411 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C084C17DB for ; Thu, 30 Aug 2018 17:25:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A495A2C2FC for ; Thu, 30 Aug 2018 17:25:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 98B802C30A; Thu, 30 Aug 2018 17:25:01 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B0B3E2C2FC for ; Thu, 30 Aug 2018 17:25:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=K4GgRRVU/VhETWaPt6JCZHsOhua7D6nu2mO1CZG35as=; b=k2Bhlb95wAAv4Xn9QxnjznLirU LWKAnWNJkqW5mHxA2uF22i8yMNU5ke7eCXbC0GM3ss6H4bUF6xFl+wixQZlrONgg/DdNkfIlkyK7b 3AvFEawVMY4r0E0TdYPXvQKkwI/F0xTAaCycR46ppEKbkf1L84dw2OROi2tcKx8Hu+ubTVSKEayGh ub9ZaaTKZv2gyYZcz+MNVTabnrr2MW2EsPTIyIdXcYFXt8XjT58AwWD13VfwvGXcoFN1U7rOvdqh3 nr+f/QZhYVj2yFP1tDu52+phGAHwyt5KkG+P84kSFw3Nkuj+SA1vqNba+R4abWz1WbL97VVVi8O1Y JaPIIRBA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fvQge-0008Rs-KR; Thu, 30 Aug 2018 17:24:52 +0000 Received: from bhuna.collabora.co.uk ([2a00:1098:0:82:1000:25:2eeb:e3e3]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fvQdD-0006q0-HP for linux-arm-kernel@lists.infradead.org; Thu, 30 Aug 2018 17:21:53 +0000 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: ezequiel) with ESMTPSA id 2CD8427D4BE From: Ezequiel Garcia To: linux-media@vger.kernel.org, linux-usb@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC 2/3] USB: core: Add non-coherent buffer allocation helpers Date: Thu, 30 Aug 2018 14:20:29 -0300 Message-Id: <20180830172030.23344-3-ezequiel@collabora.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180830172030.23344-1-ezequiel@collabora.com> References: <20180830172030.23344-1-ezequiel@collabora.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180830_102119_894424_112E39A9 X-CRM114-Status: GOOD ( 17.31 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tomasz Figa , "Matwey V . Kornilov" , Keiichi Watanabe , Alan Stern , Laurent Pinchart , kernel@collabora.com, Ezequiel Garcia MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP As noted recently by Matwey V. Kornilov, using coherent buffers on platforms _without_ hardware coherency results in some devices being completely unusable, due to transfers being too slow. Moreover, using non-coherent buffers on platforms _with_ hardware coherency, do not show a significant impact. This has been tested by Matwey on PWC USB cameras on x86_64 and ARM platforms. Quoting [1] (where kmalloc-ed buffers use streaming mappings): """ [..] average memcpy() data transfer rate (rate) and handler completion time (time) have been measured when running video stream at 640x480 resolution at 10fps. x86_64 based system (Intel Core i5-3470). This platform has hardware coherent DMA support and proposed change doesn't make big difference here. * kmalloc: rate = (2.0 +- 0.4) GBps time = (5.0 +- 3.0) usec * usb_alloc_coherent: rate = (3.4 +- 1.2) GBps time = (3.5 +- 3.0) usec armv7l based system (TI AM335x BeagleBone Black @ 300MHz). This platform has no hardware coherent DMA support. DMA coherence is implemented via disabled page caching that slows down memcpy() due to memory controller behaviour. * kmalloc: rate = (114 +- 5) MBps time = (84 +- 4) usec * usb_alloc_coherent: rate = (28.1 +- 0.1) MBps time = (341 +- 2) usec "" Introduce a pair of usb_{alloc,free}_noncoherent helper functions, for drivers that want to use non-coherent transfer buffers. [1]: https://lkml.org/lkml/2018/8/9/734 Signed-off-by: Ezequiel Garcia --- drivers/usb/core/buffer.c | 29 ++++++++++++-------- drivers/usb/core/hcd.c | 5 ++-- drivers/usb/core/usb.c | 56 +++++++++++++++++++++++++++++++++++++-- include/linux/usb.h | 5 ++++ include/linux/usb/hcd.h | 4 +-- 5 files changed, 82 insertions(+), 17 deletions(-) diff --git a/drivers/usb/core/buffer.c b/drivers/usb/core/buffer.c index 77eef8acff94..1bc9df883337 100644 --- a/drivers/usb/core/buffer.c +++ b/drivers/usb/core/buffer.c @@ -119,7 +119,8 @@ void *hcd_buffer_alloc( struct usb_bus *bus, size_t size, gfp_t mem_flags, - dma_addr_t *dma + dma_addr_t *dma, + unsigned long attrs ) { struct usb_hcd *hcd = bus_to_hcd(bus); @@ -136,18 +137,22 @@ void *hcd_buffer_alloc( return kmalloc(size, mem_flags); } - for (i = 0; i < HCD_BUFFER_POOLS; i++) { - if (size <= pool_max[i]) - return dma_pool_alloc(hcd->pool[i], mem_flags, dma); + /* Only use pools for coherent buffer requests */ + if (!attrs) { + for (i = 0; i < HCD_BUFFER_POOLS; i++) + if (size <= pool_max[i]) + return dma_pool_alloc(hcd->pool[i], + mem_flags, dma); } - return dma_alloc_coherent(hcd->self.sysdev, size, dma, mem_flags); + return dma_alloc_attrs(hcd->self.sysdev, size, dma, mem_flags, attrs); } void hcd_buffer_free( struct usb_bus *bus, size_t size, void *addr, - dma_addr_t dma + dma_addr_t dma, + unsigned long attrs ) { struct usb_hcd *hcd = bus_to_hcd(bus); @@ -163,11 +168,13 @@ void hcd_buffer_free( return; } - for (i = 0; i < HCD_BUFFER_POOLS; i++) { - if (size <= pool_max[i]) { - dma_pool_free(hcd->pool[i], addr, dma); - return; + if (!attrs) { + for (i = 0; i < HCD_BUFFER_POOLS; i++) { + if (size <= pool_max[i]) { + dma_pool_free(hcd->pool[i], addr, dma); + return; + } } } - dma_free_coherent(hcd->self.sysdev, size, addr, dma); + dma_free_attrs(hcd->self.sysdev, size, addr, dma, attrs); } diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index 1c21955fe7c0..25303738eb28 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c @@ -1383,7 +1383,7 @@ static int hcd_alloc_coherent(struct usb_bus *bus, } vaddr = hcd_buffer_alloc(bus, size + sizeof(vaddr), - mem_flags, dma_handle); + mem_flags, dma_handle, 0); if (!vaddr) return -ENOMEM; @@ -1416,7 +1416,8 @@ static void hcd_free_coherent(struct usb_bus *bus, dma_addr_t *dma_handle, if (dir == DMA_FROM_DEVICE) memcpy(vaddr, *vaddr_handle, size); - hcd_buffer_free(bus, size + sizeof(vaddr), *vaddr_handle, *dma_handle); + hcd_buffer_free(bus, size + sizeof(vaddr), + *vaddr_handle, *dma_handle, 0); *vaddr_handle = vaddr; *dma_handle = 0; diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c index 623be3174fb3..234ea5ab4bb7 100644 --- a/drivers/usb/core/usb.c +++ b/drivers/usb/core/usb.c @@ -858,6 +858,58 @@ int __usb_get_extra_descriptor(char *buffer, unsigned size, } EXPORT_SYMBOL_GPL(__usb_get_extra_descriptor); +/** + * usb_alloc_noncoherent - allocate dma-non-coherent buffer + * @dev: device the buffer will be used with + * @size: requested buffer size + * @mem_flags: affect whether allocation may block + * @dma: used to return DMA address of buffer + * + * Return: Either null (indicating no buffer could be allocated), or the + * cpu-space pointer to a non-coherent buffer that may be used to perform + * DMA to the specified device. Such cpu-space buffers are returned along + * with the DMA address (through the pointer provided). + * + * Note: + * These non-conherent buffers are used with URB_NO_xxx_DMA_MAP set in + * urb->transfer_flags to avoid using "DMA bounce buffers". When using + * this API, you must have the necessary syncs points. If you are unsure + * about this, you should be using coherent buffers via usb_alloc_coherent. + * + * When the buffer is no longer used, free it with usb_free_noncoherent(). + */ +void *usb_alloc_noncoherent(struct usb_device *dev, size_t size, gfp_t mem_flags, + dma_addr_t *dma) +{ + if (!dev || !dev->bus) + return NULL; + return hcd_buffer_alloc(dev->bus, size, + mem_flags, dma, DMA_ATTR_NON_CONSISTENT); +} +EXPORT_SYMBOL_GPL(usb_alloc_noncoherent); + +/** + * usb_free_noncoherent - free memory allocated with usb_alloc_noncoherent() + * @dev: device the buffer was used with + * @size: requested buffer size + * @addr: CPU address of buffer + * @dma: DMA address of buffer + * + * This reclaims an I/O buffer, letting it be reused. The memory must have + * been allocated using usb_alloc_noncoherent(), and the parameters must match + * those provided in that allocation request. + */ +void usb_free_noncoherent(struct usb_device *dev, size_t size, void *addr, + dma_addr_t dma) +{ + if (!dev || !dev->bus) + return; + if (!addr) + return; + hcd_buffer_free(dev->bus, size, addr, dma, DMA_ATTR_NON_CONSISTENT); +} +EXPORT_SYMBOL_GPL(usb_free_noncoherent); + /** * usb_alloc_coherent - allocate dma-consistent buffer for URB_NO_xxx_DMA_MAP * @dev: device the buffer will be used with @@ -886,7 +938,7 @@ void *usb_alloc_coherent(struct usb_device *dev, size_t size, gfp_t mem_flags, { if (!dev || !dev->bus) return NULL; - return hcd_buffer_alloc(dev->bus, size, mem_flags, dma); + return hcd_buffer_alloc(dev->bus, size, mem_flags, dma, 0); } EXPORT_SYMBOL_GPL(usb_alloc_coherent); @@ -908,7 +960,7 @@ void usb_free_coherent(struct usb_device *dev, size_t size, void *addr, return; if (!addr) return; - hcd_buffer_free(dev->bus, size, addr, dma); + hcd_buffer_free(dev->bus, size, addr, dma, 0); } EXPORT_SYMBOL_GPL(usb_free_coherent); diff --git a/include/linux/usb.h b/include/linux/usb.h index 4cdd515a4385..7fddd6c2a61e 100644 --- a/include/linux/usb.h +++ b/include/linux/usb.h @@ -1750,6 +1750,11 @@ static inline int usb_urb_dir_out(struct urb *urb) int usb_urb_ep_type_check(const struct urb *urb); +void *usb_alloc_noncoherent(struct usb_device *dev, size_t size, + gfp_t mem_flags, dma_addr_t *dma); +void usb_free_noncoherent(struct usb_device *dev, size_t size, + void *addr, dma_addr_t dma); + void *usb_alloc_coherent(struct usb_device *dev, size_t size, gfp_t mem_flags, dma_addr_t *dma); void usb_free_coherent(struct usb_device *dev, size_t size, diff --git a/include/linux/usb/hcd.h b/include/linux/usb/hcd.h index 97e2ddec18b1..41dd5f0acaad 100644 --- a/include/linux/usb/hcd.h +++ b/include/linux/usb/hcd.h @@ -486,9 +486,9 @@ int hcd_buffer_create(struct usb_hcd *hcd); void hcd_buffer_destroy(struct usb_hcd *hcd); void *hcd_buffer_alloc(struct usb_bus *bus, size_t size, - gfp_t mem_flags, dma_addr_t *dma); + gfp_t mem_flags, dma_addr_t *dma, unsigned long attrs); void hcd_buffer_free(struct usb_bus *bus, size_t size, - void *addr, dma_addr_t dma); + void *addr, dma_addr_t dma, unsigned long attrs); /* generic bus glue, needed for host controllers that don't use PCI */ extern irqreturn_t usb_hcd_irq(int irq, void *__hcd); From patchwork Thu Aug 30 17:20:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ezequiel Garcia X-Patchwork-Id: 10582399 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 04175920 for ; Thu, 30 Aug 2018 17:23:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD02B2C2D7 for ; Thu, 30 Aug 2018 17:23:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CFF542C2FC; Thu, 30 Aug 2018 17:23:37 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7AD9A2C2D7 for ; Thu, 30 Aug 2018 17:23:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=JGL7yoXkweLw43vHRXYLzGh3rdsSAuDBw9mA06MNwp4=; b=SwKlmNNKmLla1YSxUilh1UY7ZJ qih5jLA4gmb8uVqZsXSBmz+FnQu5k8j3k3r1BZEYOZlQYVJEnXSq+/dTjREP8VhTVoHcuxW8fMdWV 8FMG2SxSuWGtaaH0YBbajuJ4f+vJPDq1uDuGctvzrRvz0gCrBAGW0VHY9vssZX4k0bycfolbpxNdj cT6rJg59p2lq8DBMq/vDRCWipFYbfLiHUsMdMM61OLzqmm1TjEgaW/Ya6A5LYdcoACrs5ELzBoDvb 8v9xMnanOPU0lZHt2QDjGcdApjdyFx0+3dKKcZ0hxMtcI+j9hoYHl6FSYdJMHkPOSJgJAPDmn/s1o D5qfdWTw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fvQfH-0007r2-0r; Thu, 30 Aug 2018 17:23:27 +0000 Received: from bhuna.collabora.co.uk ([46.235.227.227]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fvQd8-0006rM-GZ for linux-arm-kernel@lists.infradead.org; Thu, 30 Aug 2018 17:21:49 +0000 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: ezequiel) with ESMTPSA id 8F0BB27D7C9 From: Ezequiel Garcia To: linux-media@vger.kernel.org, linux-usb@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC 3/3] stk1160: Use non-coherent buffers for USB transfers Date: Thu, 30 Aug 2018 14:20:30 -0300 Message-Id: <20180830172030.23344-4-ezequiel@collabora.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180830172030.23344-1-ezequiel@collabora.com> References: <20180830172030.23344-1-ezequiel@collabora.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180830_102114_720123_8C96FFA0 X-CRM114-Status: UNSURE ( 9.51 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tomasz Figa , "Matwey V . Kornilov" , Keiichi Watanabe , Alan Stern , Laurent Pinchart , kernel@collabora.com, Ezequiel Garcia MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Platforms without hardware coherency can benefit a lot from using non-coherent buffers. Moreover, platforms with hardware coherency aren't impacted by this change. For instance, on AM335x, while it's still not possible to capture full resolution frames, this patch enables half-resolution frame streams to work. Signed-off-by: Ezequiel Garcia --- drivers/media/usb/stk1160/stk1160-video.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/drivers/media/usb/stk1160/stk1160-video.c b/drivers/media/usb/stk1160/stk1160-video.c index 2811f612820f..aeb4264d1998 100644 --- a/drivers/media/usb/stk1160/stk1160-video.c +++ b/drivers/media/usb/stk1160/stk1160-video.c @@ -240,6 +240,9 @@ static void stk1160_process_isoc(struct stk1160 *dev, struct urb *urb) return; } + dma_sync_single_for_cpu(&urb->dev->dev, urb->transfer_dma, + urb->transfer_buffer_length, DMA_FROM_DEVICE); + for (i = 0; i < urb->number_of_packets; i++) { status = urb->iso_frame_desc[i].status; if (status < 0) { @@ -379,16 +382,11 @@ void stk1160_free_isoc(struct stk1160 *dev) urb = dev->isoc_ctl.urb[i]; if (urb) { - if (dev->isoc_ctl.transfer_buffer[i]) { -#ifndef CONFIG_DMA_NONCOHERENT - usb_free_coherent(dev->udev, + if (dev->isoc_ctl.transfer_buffer[i]) + usb_free_noncoherent(dev->udev, urb->transfer_buffer_length, dev->isoc_ctl.transfer_buffer[i], urb->transfer_dma); -#else - kfree(dev->isoc_ctl.transfer_buffer[i]); -#endif - } usb_free_urb(urb); dev->isoc_ctl.urb[i] = NULL; } @@ -461,12 +459,8 @@ int stk1160_alloc_isoc(struct stk1160 *dev) goto free_i_bufs; dev->isoc_ctl.urb[i] = urb; -#ifndef CONFIG_DMA_NONCOHERENT - dev->isoc_ctl.transfer_buffer[i] = usb_alloc_coherent(dev->udev, + dev->isoc_ctl.transfer_buffer[i] = usb_alloc_noncoherent(dev->udev, sb_size, GFP_KERNEL, &urb->transfer_dma); -#else - dev->isoc_ctl.transfer_buffer[i] = kmalloc(sb_size, GFP_KERNEL); -#endif if (!dev->isoc_ctl.transfer_buffer[i]) { stk1160_err("cannot alloc %d bytes for tx[%d] buffer\n", sb_size, i); @@ -490,11 +484,7 @@ int stk1160_alloc_isoc(struct stk1160 *dev) urb->interval = 1; urb->start_frame = 0; urb->number_of_packets = max_packets; -#ifndef CONFIG_DMA_NONCOHERENT urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP; -#else - urb->transfer_flags = URB_ISO_ASAP; -#endif k = 0; for (j = 0; j < max_packets; j++) {