From patchwork Fri Apr 25 17:34:13 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Catalin Marinas X-Patchwork-Id: 29116 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f71.google.com (mail-pa0-f71.google.com [209.85.220.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A91A9202E6 for ; Fri, 25 Apr 2014 17:37:17 +0000 (UTC) Received: by mail-pa0-f71.google.com with SMTP id kp14sf8574977pab.2 for ; Fri, 25 Apr 2014 10:37:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id :in-reply-to:references:cc:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:content-type:content-transfer-encoding; bh=KCHjqLUM7GIJs0FBrvK7Buj43LFvDSHTKSzKVMeE4/4=; b=B6k7M4Kb4nVbAuwNSutUPqdTidQmeE6xN8oV7w/UDFmaaLJrdRkUk+jV3iArBnONgj 5GWD4RfRiiQkUF5UJ1AllmI0oYVw+wEuvMJvTsh1guommgBrD8qHURECiMfn3gLBJlft EDI1+CsGa24yhrOHHwiZOSJPHVLFWzuX1G61S8y5xfaKVsLHofh9PoJJz+zmhpjCwFUF VRrRoQG9IRT0+9AovQf1rvPCTesdQEUI9Hv27+ySE50uNsPYcoaayawbMQELIimVRK0V qnkA9K70a6acE4J9DfjU4OjNrlVZfKR6+h3KUDG8NWIZ1F8UuFEO3RhP/jhjbq0sgZaJ pyBw== X-Gm-Message-State: ALoCoQkMCr7SXTH5M1Q31S9+Tz1+5FrAWc/dkrLR03DbDHOZacIZ6A/h23yg8D48iUpXCKs1i+TJ X-Received: by 10.66.254.101 with SMTP id ah5mr574434pad.8.1398447436966; Fri, 25 Apr 2014 10:37:16 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.41.212 with SMTP id z78ls1731907qgz.93.gmail; Fri, 25 Apr 2014 10:37:16 -0700 (PDT) X-Received: by 10.52.104.7 with SMTP id ga7mr6475012vdb.29.1398447436806; Fri, 25 Apr 2014 10:37:16 -0700 (PDT) Received: from mail-vc0-f174.google.com (mail-vc0-f174.google.com [209.85.220.174]) by mx.google.com with ESMTPS id sq9si1853769vdc.143.2014.04.25.10.37.16 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 25 Apr 2014 10:37:16 -0700 (PDT) Received-SPF: none (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) client-ip=209.85.220.174; Received: by mail-vc0-f174.google.com with SMTP id ld13so5073554vcb.19 for ; Fri, 25 Apr 2014 10:37:16 -0700 (PDT) X-Received: by 10.58.126.4 with SMTP id mu4mr7798872veb.0.1398447436708; Fri, 25 Apr 2014 10:37:16 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp115447vcb; Fri, 25 Apr 2014 10:37:16 -0700 (PDT) X-Received: by 10.224.6.10 with SMTP id 10mr13523716qax.45.1398447436355; Fri, 25 Apr 2014 10:37:16 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id i1si4182202qab.205.2014.04.25.10.37.16 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 Apr 2014 10:37:16 -0700 (PDT) Received-SPF: none (google.com: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org does not designate permitted sender hosts) client-ip=2001:1868:205::9; 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 1Wdk2D-0006Tq-QH; Fri, 25 Apr 2014 17:35:37 +0000 Received: from fw-tnat.cambridge.arm.com ([217.140.96.21] helo=cam-smtp0.cambridge.arm.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Wdk1q-0005CC-PY for linux-arm-kernel@lists.infradead.org; Fri, 25 Apr 2014 17:35:15 +0000 Received: from e102109-lin.cambridge.arm.com (e102109-lin.cambridge.arm.com [10.1.203.182]) by cam-smtp0.cambridge.arm.com (8.13.8/8.13.8) with ESMTP id s3PHYgMC023866; Fri, 25 Apr 2014 18:34:43 +0100 From: Catalin Marinas To: linux-arm-kernel@lists.infradead.org Subject: [PATCH 2/3] arm64: Use bus notifiers to set per-device coherent DMA ops Date: Fri, 25 Apr 2014 18:34:13 +0100 Message-Id: <1398447254-18527-3-git-send-email-catalin.marinas@arm.com> X-Mailer: git-send-email 1.7.12.3 In-Reply-To: <1398447254-18527-1-git-send-email-catalin.marinas@arm.com> References: <1398447254-18527-1-git-send-email-catalin.marinas@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140425_103515_190160_99205C29 X-CRM114-Status: GOOD ( 12.85 ) X-Spam-Score: -1.4 (-) X-Spam-Report: SpamAssassin version 3.3.2 on bombadil.infradead.org summary: Content analysis details: (-1.4 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [217.140.96.21 listed in list.dnswl.org] -0.7 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -0.0 SPF_PASS SPF: sender matches SPF record Cc: Loc Ho X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 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+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: catalin.marinas@arm.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Recently, the default DMA ops have been changed to non-coherent for alignment with 32-bit ARM platforms (and DT files). This patch adds bus notifiers to be able to set the coherent DMA ops (with no cache maintenance) for devices explicitly marked as coherent via the "dma-coherent" DT property. Signed-off-by: Catalin Marinas --- arch/arm64/kernel/setup.c | 2 +- arch/arm64/mm/dma-mapping.c | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index 720853f70b6b..b89e4914b7e4 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -397,7 +397,7 @@ static int __init arm64_device_init(void) of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL); return 0; } -arch_initcall(arm64_device_init); +arch_initcall_sync(arm64_device_init); static DEFINE_PER_CPU(struct cpu, cpu_data); diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c index 1f65963a9c04..c851eb44dc50 100644 --- a/arch/arm64/mm/dma-mapping.c +++ b/arch/arm64/mm/dma-mapping.c @@ -22,8 +22,11 @@ #include #include #include +#include +#include #include #include +#include #include @@ -305,17 +308,45 @@ struct dma_map_ops coherent_swiotlb_dma_ops = { }; EXPORT_SYMBOL(coherent_swiotlb_dma_ops); +static int dma_bus_notifier(struct notifier_block *nb, + unsigned long event, void *_dev) +{ + struct device *dev = _dev; + + 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); + + return NOTIFY_OK; +} + +static struct notifier_block platform_bus_nb = { + .notifier_call = dma_bus_notifier, +}; + +static struct notifier_block amba_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) { size_t swiotlb_size = min(SZ_64M, MAX_ORDER_NR_PAGES << PAGE_SHIFT); + /* + * These must be registered before of_platform_populate(). + */ + bus_register_notifier(&platform_bus_type, &platform_bus_nb); + bus_register_notifier(&amba_bustype, &amba_bus_nb); + dma_ops = &noncoherent_swiotlb_dma_ops; return swiotlb_late_init_with_default_size(swiotlb_size); } -subsys_initcall(swiotlb_late_init); +arch_initcall(swiotlb_late_init); #define PREALLOC_DMA_DEBUG_ENTRIES 4096