From patchwork Fri Sep 19 15:51:26 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Salter X-Patchwork-Id: 4938671 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id DD541BEEA5 for ; Fri, 19 Sep 2014 15:54:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F2505201F2 for ; Fri, 19 Sep 2014 15:54:01 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 16230201C8 for ; Fri, 19 Sep 2014 15:54:01 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XV0TX-0002ur-N4; Fri, 19 Sep 2014 15:51:59 +0000 Received: from mx1.redhat.com ([209.132.183.28]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XV0TV-0002pp-B4 for linux-arm-kernel@lists.infradead.org; Fri, 19 Sep 2014 15:51:57 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s8JFpV77008765 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 19 Sep 2014 11:51:32 -0400 Received: from deneb.redhat.com (ovpn-113-98.phx2.redhat.com [10.3.113.98]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s8JFpUZ8027032; Fri, 19 Sep 2014 11:51:30 -0400 From: Mark Salter To: Catalin Marinas , Will Deacon Subject: [PATCH] arm64/pci: fix dma coherency inheritance for PCI devices Date: Fri, 19 Sep 2014 11:51:26 -0400 Message-Id: <1411141886-11310-1-git-send-email-msalter@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140919_085157_425037_E5FE955D X-CRM114-Status: GOOD ( 15.16 ) X-Spam-Score: -5.7 (-----) Cc: Jon Masters , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Mark Salter X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The default dma_ops for devices on arm64 systems are noncoherent in nature and rely upon special operations and bounce buffers to perform a device DMA operation to/from memory. Some drivers rely upon coherent operations involving suitably capable hardware. In this case, a "dma-coherent" property will exist on the corresponding Device Tree node for the bridge device, or one of its ancestors. This patch adds support for applying a DMA coherent dma_ops for PCI devices in the case of such a property. Signed-off-by: Jon Masters [added search for device with of_node] Signed-off-by: Mark Salter --- arch/arm64/mm/dma-mapping.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c index 4164c5a..0e26bd7 100644 --- a/arch/arm64/mm/dma-mapping.c +++ b/arch/arm64/mm/dma-mapping.c @@ -23,10 +23,12 @@ #include #include #include +#include #include #include #include #include +#include #include @@ -316,8 +318,18 @@ static int dma_bus_notifier(struct notifier_block *nb, if (event != BUS_NOTIFY_ADD_DEVICE) return NOTIFY_DONE; - if (of_property_read_bool(dev->of_node, "dma-coherent")) - set_dma_ops(dev, &coherent_swiotlb_dma_ops); + /* + * Some devices won't have an of_node but a bus controller/bridge will. + * Search up the device chain until we find an of_node to check. + */ + while (dev) { + if (dev->of_node) { + if (of_dma_is_coherent(dev->of_node)) + set_dma_ops(_dev, &coherent_swiotlb_dma_ops); + break; + } + dev = dev->parent; + } return NOTIFY_OK; } @@ -330,6 +342,10 @@ static struct notifier_block amba_bus_nb = { .notifier_call = dma_bus_notifier, }; +static struct notifier_block pci_bus_nb = { + .notifier_call = dma_bus_notifier, +}; + extern int swiotlb_late_init_with_default_size(size_t default_size); static int __init swiotlb_late_init(void) @@ -341,6 +357,7 @@ static int __init swiotlb_late_init(void) */ bus_register_notifier(&platform_bus_type, &platform_bus_nb); bus_register_notifier(&amba_bustype, &amba_bus_nb); + bus_register_notifier(&pci_bus_type, &pci_bus_nb); dma_ops = &noncoherent_swiotlb_dma_ops;