76c736
From patchwork Thu Jan 24 12:06:58 2019
76c736
Content-Type: text/plain; charset="utf-8"
76c736
MIME-Version: 1.0
76c736
Content-Transfer-Encoding: 7bit
76c736
X-Patchwork-Submitter: Ard Biesheuvel <ard.biesheuvel@linaro.org>
76c736
X-Patchwork-Id: 10778815
76c736
Return-Path: 
76c736
 <linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org>
76c736
Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org
76c736
 [172.30.200.125])
76c736
	by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B27A191E
76c736
	for <patchwork-linux-arm@patchwork.kernel.org>;
76c736
 Thu, 24 Jan 2019 12:07:20 +0000 (UTC)
76c736
Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1])
76c736
	by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DFBE72EC6C
76c736
	for <patchwork-linux-arm@patchwork.kernel.org>;
76c736
 Thu, 24 Jan 2019 12:07:17 +0000 (UTC)
76c736
Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486)
76c736
	id D30BC2ECE2; Thu, 24 Jan 2019 12:07:17 +0000 (UTC)
76c736
X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on
76c736
	pdx-wl-mail.web.codeaurora.org
76c736
X-Spam-Level: 
76c736
X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED,
76c736
	DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1
76c736
Received: from bombadil.infradead.org (bombadil.infradead.org
76c736
 [198.137.202.133])
76c736
	(using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits))
76c736
	(No client certificate requested)
76c736
	by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C03122EC6C
76c736
	for <patchwork-linux-arm@patchwork.kernel.org>;
76c736
 Thu, 24 Jan 2019 12:07:16 +0000 (UTC)
76c736
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;
76c736
	d=lists.infradead.org; s=bombadil.20170209; h=Sender:
76c736
	Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post:
76c736
	List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To
76c736
	:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:
76c736
	Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:
76c736
	List-Owner; bh=xo5AgoUtS0FBdf9ZXAO75L7eu+GEGqebznBMcwnNXS0=; b=EUK2XskaTLLGNd
76c736
	PLBm/AVgfZr2j3GzaOOAh6rJqVHuQ4k98saArkFu8aSFtVkvkSPF3PKCDKnV+7mZibl17Kqiup2Cv
76c736
	HsRzfxwZzeksoNjDcZMYK82pttYA+iizpIYq16Wp+SXMzm6HRuku9XhW7tygG9zNr+cUVzaN6QU6b
76c736
	mO5CAPgeGsluExNwC+4i4fRNqtN4z7rTMPuHkZ6jSy6tTy/OyKUApjhrgphDWEjtelAKeqn8Jwg+i
76c736
	YnZQMi8l6B4Ffn7IlU2wHVKU7/yk9hO46AC+uKKYTV5RmcC0xFqKNK0TnBQzum5FdK2/h7h/3f0CA
76c736
	GflIczkPfOItaFoJvs3g==;
76c736
Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org)
76c736
	by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux))
76c736
	id 1gmdmr-0000p2-1K; Thu, 24 Jan 2019 12:07:13 +0000
76c736
Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341])
76c736
 by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux))
76c736
 id 1gmdmm-0000oP-Sk
76c736
 for linux-arm-kernel@lists.infradead.org; Thu, 24 Jan 2019 12:07:11 +0000
76c736
Received: by mail-wm1-x341.google.com with SMTP id b11so2875125wmj.1
76c736
 for <linux-arm-kernel@lists.infradead.org>;
76c736
 Thu, 24 Jan 2019 04:07:07 -0800 (PST)
76c736
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google;
76c736
 h=from:to:cc:subject:date:message-id:mime-version
76c736
 :content-transfer-encoding;
76c736
 bh=GsPSU83pbk1uWSobF359Hmb25tSiPCSXYSiAdhiX2K0=;
76c736
 b=MVHv9eioSsA83BVb2J9fi21oGdNAhe8L5mYX67nd+XBNW59IxbYWyPCjLtaUXXFxQx
76c736
 C8eDCimc2jtV5LiHYUHkJKhoQYN40/4u2K6EOoUunE10yy3C+J6aGY9JX5gh7mgstcNp
76c736
 Dvdm9CHYXs35/N3s4bzP1fUHVnLbpVKVammw0=
76c736
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
76c736
 d=1e100.net; s=20161025;
76c736
 h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version
76c736
 :content-transfer-encoding;
76c736
 bh=GsPSU83pbk1uWSobF359Hmb25tSiPCSXYSiAdhiX2K0=;
76c736
 b=DtNKUeOnwDAjpgolmP7hnQugxkX3XqgSxg6WUAlVeQyxIk+8QlEAWLNFtKPL57EnLP
76c736
 G9R1qiTnF1TI4PM8DFH+URNkVNcI9hvhGKtO4fya+BjPd6dqPJVwct1+KZWM8lTJfDX+
76c736
 pMKL1ZiDeYMlHAMkd2CfCckaEptq5FjtvwJ8pyPbdN5qNxVJ6CEPIl9HORWWMuwrsxaj
76c736
 xo5MK/UpOqhomOXRe5WxGor2JPNit68hT1PvHQwqNXCoRRTtCUANoV7s1nJ2Ad+pkhV7
76c736
 FW5IV/JnVetKbeCIhe2I/m6VlJ+6x3wPOpiWN/Fd8z5tYX0zI0vjKqdjdfr/QJCNF69Z
76c736
 +cuw==
76c736
X-Gm-Message-State: AJcUukcCDAeH11orvgS33hS4OKLhp1Vglp0ChrGS5Ol91KaBPDqURaLX
76c736
 WKQRIEAwB4phU3pS/I/nkTBzdQ==
76c736
X-Google-Smtp-Source: 
76c736
 ALg8bN55gm82WRKfoWS5g8dy3rATbR8W4MaKwupN1EALKBkI9t9KdMSE60V2HSnI4wy7yU44++cGoA==
76c736
X-Received: by 2002:a1c:bdc5:: with SMTP id n188mr2530824wmf.69.1548331626262;
76c736
 Thu, 24 Jan 2019 04:07:06 -0800 (PST)
76c736
Received: from localhost.localdomain
76c736
 (laubervilliers-657-1-83-120.w92-154.abo.wanadoo.fr. [92.154.90.120])
76c736
 by smtp.gmail.com with ESMTPSA id t12sm98842348wrr.65.2019.01.24.04.07.04
76c736
 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
76c736
 Thu, 24 Jan 2019 04:07:05 -0800 (PST)
76c736
From: Ard Biesheuvel <ard.biesheuvel@linaro.org>
76c736
To: linux-kernel@vger.kernel.org
76c736
Subject: [PATCH] drm: enable uncached DMA optimization for ARM and arm64
76c736
Date: Thu, 24 Jan 2019 13:06:58 +0100
76c736
Message-Id: <20190124120658.30288-1-ard.biesheuvel@linaro.org>
76c736
X-Mailer: git-send-email 2.20.1
76c736
MIME-Version: 1.0
76c736
X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 
76c736
X-CRM114-CacheID: sfid-20190124_040708_952827_D4810358 
76c736
X-CRM114-Status: GOOD (  13.64  )
76c736
X-BeenThere: linux-arm-kernel@lists.infradead.org
76c736
X-Mailman-Version: 2.1.21
76c736
Precedence: list
76c736
List-Id: <linux-arm-kernel.lists.infradead.org>
76c736
List-Unsubscribe: 
76c736
 <http: lists.infradead.org="" mailman="" options="" linux-arm-kernel="">,
76c736
 <mailto:linux-arm-kernel-request@lists.infradead.org?subject=unsubscribe>
76c736
List-Archive: <http: lists.infradead.org="" pipermail="" linux-arm-kernel=""/>
76c736
List-Post: <mailto:linux-arm-kernel@lists.infradead.org>
76c736
List-Help: <mailto:linux-arm-kernel-request@lists.infradead.org?subject=help>
76c736
List-Subscribe: 
76c736
 <http: lists.infradead.org="" mailman="" listinfo="" linux-arm-kernel="">,
76c736
 <mailto:linux-arm-kernel-request@lists.infradead.org?subject=subscribe>
76c736
Cc: David Zhou <david1.zhou@amd.com>,
76c736
 Maxime Ripard <maxime.ripard@bootlin.com>,
76c736
 Benjamin Herrenschmidt <benh@kernel.crashing.org>,
76c736
 Carsten Haitzler <carsten.haitzler@arm.com>,
76c736
 Ard Biesheuvel <ard.biesheuvel@linaro.org>, David Airlie <airlied@linux.ie>,
76c736
 Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
76c736
 dri-devel <dri-devel@lists.freedesktop.org>,
76c736
 Michel Daenzer <michel.daenzer@amd.com>, Robin Murphy <robin.murphy@arm.com>,
76c736
 Will Deacon <will.deacon@arm.com>, Christoph Hellwig <hch@infradead.org>,
76c736
 Junwei Zhang <jerry.zhang@amd.com>, Huang Rui <ray.huang@amd.com>,
76c736
 amd-gfx list <amd-gfx@lists.freedesktop.org>,
76c736
 Daniel Vetter <daniel@ffwll.ch>,
76c736
 Michael Ellerman <mpe@ellerman.id.au>,
76c736
 Alex Deucher <alexander.deucher@amd.com>, Sean Paul <sean@poorly.run>,
76c736
 Christian Koenig <christian.koenig@amd.com>,
76c736
 linux-arm-kernel@lists.infradead.org
76c736
Content-Type: text/plain; charset="us-ascii"
76c736
Sender: "linux-arm-kernel" <linux-arm-kernel-bounces@lists.infradead.org>
76c736
Errors-To: 
76c736
 linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org
76c736
X-Virus-Scanned: ClamAV using ClamSMTP
76c736
76c736
The DRM driver stack is designed to work with cache coherent devices
76c736
only, but permits an optimization to be enabled in some cases, where
76c736
for some buffers, both the CPU and the GPU use uncached mappings,
76c736
removing the need for DMA snooping and allocation in the CPU caches.
76c736
76c736
The use of uncached GPU mappings relies on the correct implementation
76c736
of the PCIe NoSnoop TLP attribute by the platform, otherwise the GPU
76c736
will use cached mappings nonetheless. On x86 platforms, this does not
76c736
seem to matter, as uncached CPU mappings will snoop the caches in any
76c736
case. However, on ARM and arm64, enabling this optimization on a
76c736
platform where NoSnoop is ignored results in loss of coherency, which
76c736
breaks correct operation of the device. Since we have no way of
76c736
detecting whether NoSnoop works or not, just disable this
76c736
optimization entirely for ARM and arm64.
76c736
76c736
Cc: Christian Koenig <christian.koenig@amd.com>
76c736
Cc: Alex Deucher <alexander.deucher@amd.com>
76c736
Cc: David Zhou <david1.zhou@amd.com>
76c736
Cc: Huang Rui <ray.huang@amd.com>
76c736
Cc: Junwei Zhang <jerry.zhang@amd.com>
76c736
Cc: Michel Daenzer <michel.daenzer@amd.com>
76c736
Cc: David Airlie <airlied@linux.ie>
76c736
Cc: Daniel Vetter <daniel@ffwll.ch>
76c736
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
76c736
Cc: Maxime Ripard <maxime.ripard@bootlin.com>
76c736
Cc: Sean Paul <sean@poorly.run>
76c736
Cc: Michael Ellerman <mpe@ellerman.id.au>
76c736
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
76c736
Cc: Will Deacon <will.deacon@arm.com>
76c736
Cc: Christoph Hellwig <hch@infradead.org>
76c736
Cc: Robin Murphy <robin.murphy@arm.com>
76c736
Cc: amd-gfx list <amd-gfx@lists.freedesktop.org>
76c736
Cc: dri-devel <dri-devel@lists.freedesktop.org>
76c736
Reported-by: Carsten Haitzler <carsten.haitzler@arm.com>
76c736
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
76c736
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
76c736
---
76c736
 include/drm/drm_cache.h | 18 ++++++++++++++++++
76c736
 1 file changed, 18 insertions(+)
76c736
76c736
diff --git a/include/drm/drm_cache.h b/include/drm/drm_cache.h
76c736
index bfe1639df02d..97fc498dc767 100644
76c736
--- a/include/drm/drm_cache.h
76c736
+++ b/include/drm/drm_cache.h
76c736
@@ -47,6 +47,24 @@ static inline bool drm_arch_can_wc_memory(void)
76c736
 	return false;
76c736
 #elif defined(CONFIG_MIPS) && defined(CONFIG_CPU_LOONGSON3)
76c736
 	return false;
76c736
+#elif defined(CONFIG_ARM) || defined(CONFIG_ARM64)
76c736
+	/*
76c736
+	 * The DRM driver stack is designed to work with cache coherent devices
76c736
+	 * only, but permits an optimization to be enabled in some cases, where
76c736
+	 * for some buffers, both the CPU and the GPU use uncached mappings,
76c736
+	 * removing the need for DMA snooping and allocation in the CPU caches.
76c736
+	 *
76c736
+	 * The use of uncached GPU mappings relies on the correct implementation
76c736
+	 * of the PCIe NoSnoop TLP attribute by the platform, otherwise the GPU
76c736
+	 * will use cached mappings nonetheless. On x86 platforms, this does not
76c736
+	 * seem to matter, as uncached CPU mappings will snoop the caches in any
76c736
+	 * case. However, on ARM and arm64, enabling this optimization on a
76c736
+	 * platform where NoSnoop is ignored results in loss of coherency, which
76c736
+	 * breaks correct operation of the device. Since we have no way of
76c736
+	 * detecting whether NoSnoop works or not, just disable this
76c736
+	 * optimization entirely for ARM and arm64.
76c736
+	 */
76c736
+	return false;
76c736
 #else
76c736
 	return true;
76c736
 #endif