From nobody Tue Sep 29 18:56:40 2026 Received: from fhigh-a2-smtp.messagingengine.com (fhigh-a2-smtp.messagingengine.com [103.168.172.153]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D52EE3BADA7; Wed, 19 Aug 2026 14:52:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787151175; cv=none; b=H41fE6GM64mDiNbHXsRMjNy/5ksRrTaJg/oRhUqSF8uYiBFfkkh5IpbgKht0w4CzUFw2i/qsyPv5bxO2/RGOWxBXLKn9WCsFGZci4BQBgWeGTFH8fcU1iEz74mddmPzRruXvkP7DKSj+w5fYP23+3h0T9qBIAxIZOzhKp5qRPEA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787151175; c=relaxed/simple; bh=8Rv9OVc1AW97l/UiCVzPt+gRZOTmtkExTv7zaq6GYSo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hy3bUzO84MmXX6N5ZNALnhKr18L90XxYiMMeSxZyZFhiQoJ6075imDxiU2D/xUvCn0TueOxROso9mmbGmPlbJARGL8dDSYAdKrwfN9ErJnH+JhWenSvnIVT4VdvFaHF219Z/E7v3i26/T1IZQ8BQ4NRGCfmOWD1VZBdF/rii7PE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=jannau.net; spf=pass smtp.mailfrom=jannau.net; dkim=pass (2048-bit key) header.d=jannau.net header.i=@jannau.net header.b=A16exu78; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=PYNGuHvi; arc=none smtp.client-ip=103.168.172.153 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=jannau.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=jannau.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=jannau.net header.i=@jannau.net header.b="A16exu78"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="PYNGuHvi" Received: from phl-compute-12.internal (phl-compute-12.internal [10.202.2.52]) by mailfhigh.phl.internal (Postfix) with ESMTP id 17E9B1400124; Wed, 19 Aug 2026 10:52:53 -0400 (EDT) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-12.internal (MEProxy); Wed, 19 Aug 2026 10:52:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jannau.net; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1787151173; x=1787237573; bh=QR9hH2qCFCqj8AmL9TfSa9UfhVhgFX2hAhjrgRMsWck=; b= A16exu78qsBFxlFrBx+sy4cDIIZAlNSdpNBFjB4oTYD6DtEJlMztplDfHCXKYA4I eA0i7DReouXRP+mQNaP6o/uFLCxM4JpVhHdUHaUr3tuXY/cT1hvuXgG9nUWzKo3U 9WsRddvYLrNQIQC6O+49uurlQKHx5YXb7lOBX9aXoyHQH1dcaPxDd0FNFLGBHLg+ VQACfPOury8/YSGCywqy+ByJPdxr6hXaCHiJWW5QU5A/Xj8IQJKzycHcpZA2HJZf 49jCRambZQcaWFuyGC9pmeE92sAysyJRbgPoq1IP3Trt5+9d1E8H/o++Nn8enuZw FtkeufY9SUCOSKt5pU/etA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1787151173; x= 1787237573; bh=QR9hH2qCFCqj8AmL9TfSa9UfhVhgFX2hAhjrgRMsWck=; b=P YNGuHvi46DPBuJLAtJptkiAxE+cbnI4/aEjB3ZMXJC05z9+nIedduwpWDxG7JdX3 HElp+PwAatO4eCFe7dLTOWCEi/5FAw0yjO5QI+7fmTQ3yhjE19I9z/pHHER8iwBG GX+V8d7RlgX5rfZ/scEsmKRNV+kDLrf3EwCyqOWYk4lgKD4xVN3HZl71OET/7VFI 5/EvbvggHP96q1aBM4pSLs8iunuXSXaQ5Eq87Sn77TLl4Z817hv6EyS++j83Gh1h +AR4B4vANlz96QfaNWvFyYK7ahXgRZOAJS5h5gm92doLWjejVoVYF5q8w96cOwoy t8GgjdYDwr5YmQYZHB1XQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTFxm+5+zXIrX7B4RAkbJJNgS9ypMPi3z8gh3rlPLNt4LxM9cDQcT3/2Bcp5LPXrd2 bzLP10mTv1erjlWchiwV2T1kZOH7q731/O+CSyOXY9jGJa8fQeY8GfAfIrdbonVv+niAK8 Ulv4q3lWMzQHlJS2orLhRlyISYSMgJezzLinQQddNx9zca5cCQ4G+rS6i21cd/pzp/wCeh Hy41Gj5mYTgnqNUtEpn4VpJRo7M/dbuYpk3oOLnuChKh+xWd0dci8SOZ5j6n8tCbr/1bqn BseM5n9b0HhpGfo+RvV8SrST9+9LYZOD09vW7LlZI3nMn8KWINeVhuAhRZwiyo7Xz7Mil9 gt+Hh4PuoOpoTY6+MZxKOoUS1xc34TE5uVdMGzFGzms11Vy4Buui27GQosVF4AHo5JIpkt 3PjmtYGDvxMiG4uDlZtg3lraltpfwCgRRG+KYQe4+F64oSw4nVxeNQR+vEqb/zW5OxnWDj FHYJb2GL2AKFFBRq7YHaRKpo+wOXNNBKWsJoX+tDlLXnpd1iroqMnBkouXQfi+7JicBFcS aRP8Ktinae6pTpthL0VzovwmTIGaPS4tGkxmDFRGlxe75pzVOREKHox1ji0QTRr7/QFEZe fI+m5u3uehx57UsyTIJA/Jxn1kosN2yw/ndJfMTgOF3Kixn4E4C2KHTDdIsA X-ME-Proxy: Feedback-ID: i47b949f6:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 19 Aug 2026 10:52:52 -0400 (EDT) From: Janne Grunau Date: Wed, 19 Aug 2026 16:52:27 +0200 Subject: [PATCH 1/2] dt-bindings: iommu: dart: Support specifying the DMA aperture Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260819-iommu-apple-dart-aperture-v1-1-252703f381aa@jannau.net> References: <20260819-iommu-apple-dart-aperture-v1-0-252703f381aa@jannau.net> In-Reply-To: <20260819-iommu-apple-dart-aperture-v1-0-252703f381aa@jannau.net> To: Sven Peter , Neal Gompa , "Joerg Roedel (AMD)" , Will Deacon , Robin Murphy , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org, iommu@lists.linux.dev, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Janne Grunau X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=2153; i=j@jannau.net; s=yk2025; h=from:subject:message-id; bh=8Rv9OVc1AW97l/UiCVzPt+gRZOTmtkExTv7zaq6GYSo=; b=owGbwMvMwCW2UNrmdq9+ahrjabUkhqzWw/a6t9ZdXi7k9frkh5U3N+iEta3s77m8YotGcPk34 whn5cNfOkpZGMS4GGTFFFmStF92MKyuUYypfRAGM4eVCWQIAxenAEzE8THDX+ni20suWHbWpYe3 rNy+4dYi92v8QpExG3e4/Pvpfd/+QQkjQ8vLE8szC0v/b27+8sw3jk+oxa+S4aSw1m/ey5FlHj7 /WAA= X-Developer-Key: i=j@jannau.net; a=openpgp; fpr=8B336A6BE4E5695E89B8532B81E806F586338419 Apple DARTs are often connected directly to devices that expect only a portion of their address space to be used for DMA (for example, because other ranges are mapped directly to something else). Follow the "#iommu-cells =3D <4>" example from iommu.txt and allow specifying the DMA aperture via additional cells. Since DART is used on 64-bit Apple silicon systems use two cells to specify the start and length of the aperture. A common aperture starts at 0x100_0000_0000 and spans a 36-bit address space. This corresponds to the vm-base and vm-size properties on the Apple device tree side of things. As not all devices require this and to keep compatibility with existing device trees allow 1 and 5 as values for #iommu-cells. Signed-off-by: Janne Grunau --- Documentation/devicetree/bindings/iommu/apple,dart.yaml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Documentation/devicetree/bindings/iommu/apple,dart.yaml b/Docu= mentation/devicetree/bindings/iommu/apple,dart.yaml index 47ec7fa52c3a..6efbe732b4ce 100644 --- a/Documentation/devicetree/bindings/iommu/apple,dart.yaml +++ b/Documentation/devicetree/bindings/iommu/apple,dart.yaml @@ -44,10 +44,12 @@ properties: Optional since not all IOMMUs are attached to a clock gate. =20 '#iommu-cells': - const: 1 + enum: [ 1, 5 ] description: - Has to be one. The single cell describes the stream id emitted by - a master to the IOMMU. + Has to be one or five. The first cell describes the stream id emitte= d by + a master to the IOMMU. The optional second and third cell describe t= he + aperture start of a master's DMA window and fourth and fifth cell de= scribe + the size of DMA window. =20 power-domains: maxItems: 1 @@ -66,11 +68,11 @@ examples: compatible =3D "apple,t8103-dart"; reg =3D <0x82f80000 0x4000>; interrupts =3D <1 781 4>; - #iommu-cells =3D <1>; + #iommu-cells =3D <5>; }; =20 master1 { - iommus =3D <&dart1 0>; + iommus =3D <&dart1 0 0x100 0x0 0x10 0x0>; }; =20 - |+ --=20 2.55.0 From nobody Tue Sep 29 18:56:40 2026 Received: from fhigh-a2-smtp.messagingengine.com (fhigh-a2-smtp.messagingengine.com [103.168.172.153]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DBEF6477986; Wed, 19 Aug 2026 14:52:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787151179; cv=none; b=BsqTisPkdtUF1+13+FibTZu0jX/pna3Za346S2jsESGtyjEnilaBy4Dznpgi88SJb0a8kWFf5E4+aGYoaqOqGiZCxA7nIAo/3L8nsdugX691nKvWS3NAsgt9fVM8e32UbxRQVDlwbonSHFCYNZOUqexwRwej3Ad83nFoGMp+Hrk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787151179; c=relaxed/simple; bh=FbyOzRgdywKDBHRx8l02hzwwB8bqNEhHNRkH6Xxlqxw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HkhjHzy2zm0xCw16888rFstzEwOtS1eSM2YZErFyglbCOGokNmoSvc7uJE8VUunksYQkGRZAsOHjBnJLpeH3AwuJ4QJwE4y9Ow+/4+l6ofYhgt7HcSKDiXLmerNtNgyx0W0oBBHrYZE2PvTdXWtNezYoyVgnzX+ABAZP//uwtWA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=jannau.net; spf=pass smtp.mailfrom=jannau.net; dkim=pass (2048-bit key) header.d=jannau.net header.i=@jannau.net header.b=Gi2upZBG; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=UtLLicWf; arc=none smtp.client-ip=103.168.172.153 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=jannau.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=jannau.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=jannau.net header.i=@jannau.net header.b="Gi2upZBG"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="UtLLicWf" Received: from phl-compute-03.internal (phl-compute-03.internal [10.202.2.43]) by mailfhigh.phl.internal (Postfix) with ESMTP id 04FE1140014F; Wed, 19 Aug 2026 10:52:55 -0400 (EDT) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Wed, 19 Aug 2026 10:52:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jannau.net; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1787151175; x=1787237575; bh=cWJ7YipM5dUZEBUb+Zs3mE2xmmW2oTemPngyFleNW74=; b= Gi2upZBGJtT9Hqkyr9rnkScRzgxAPY+ZBp5p+ZmVTv6NBvJ6T2nWqkqWZRXp0F6F GCOWqPu/rljgtMFMyj1t9RGvlXNA5e4RBGfWYnH0SkHMcu4Tvq7+1o7i9p2vbWxG teEQhPXkGqx6jCzEQLyaXqRTvEAJtxFIut3gMx7TfnGlLF8GvWsC2LoGyzfF9zL3 oJ1WloCTmxv7Grh8bUlafegQpU4uJOFEBGMdiV8jxMjRoMcHm3V9UbZGrrnuhOKj Jd1nP3t/23BxC9n6usDc6243EUH6IEzY2JWj0BtGFKQiLMrhfYsbVse/jfeX6YO8 hHghUU0jZtzC9zkETeP8JQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1787151175; x= 1787237575; bh=cWJ7YipM5dUZEBUb+Zs3mE2xmmW2oTemPngyFleNW74=; b=U tLLicWf0ULZdYAjrmBqvR41givFVHxVv64Qxghz1uKC8F4WC5x6KuVtQwMMyPpmr hMkLO7ylo82Xo8tVbRBWSXhSTj3dKDBtbQ0dw0xCxcSoPYdmB7XtqL1MeqeDYQCY FHglyouGlRt1e2+d4/NniUjd5vc7KUG6nhB6eoe5A1SPKAzVemAXKlIPKxwcQcJc iiN1Ru5GpduxipjvunvCmxsrwSuo2RQgpzua+WpfkcjokExbDLGT8ZHISW3e2SI7 hbu//Fdlbt3aiB080boh3q+P2NnnjSz9G/ujEZrZY+LU9Z0xito1Ks4MW+MxvBW1 NJQmq1tPlLz2g8rkslWDA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTE9TViwfq+braXum8jXlJNh6tjfJssH5OCKEStoqwW04qQEaTL3gCCfAPdgPpcaW1 pEharjtJlrCMhTSjNcYokOC3LxLmv5k6jCaTOqTYBEU3vhWxeKKuzyTu6NxdaEPiGvLvqn tk+JWyJuiTaTBDoyzuuSiWQ7uiu+fI8K67zHGsiXtgIbdVCAvjBtq1r6V25uQf2tFWplnV db1tw8RMwX7E0nhaCeQIWbNUfVRayGesgwU2vp2wbhjaK2rJX2kWsR+GBsDKsedTKLNhf1 NmN+JtT9Vn2ozOLHqwmD79wtlkHlz3Hm/WivkLeA3EW0JrcrCwuRDevSQEd2pd3xeUdwty r1TAP7yGqK1aW1uHFLgUU13cBiUX+kM5PANz/kQ26hFsLIlreu1TXiVVRlEcM2HmyZ9KAs 5vTd4w+1Pi4oIcVqTcXJTz9Kf5nzlUtzWsV+cJ0bizznq+PA3qcuXx/zUoNVHUhWXZ6zSC qiz+27y86DDY+iAUjMb+dwJFkC27USE9ieU37Oe9HxE1XNgk3EYp1G6LO3Rmb0n0RDeuX3 4udE0P4HTkKhgC1Wq0Gxogh3HUsG2+li02XT8vaA9nv/RxouwH2o8hTBuWoqk56B07HGpx 1k7bFqmli+M1y5QLWUzVSwoibXgsgP/yrKHlJUMgg4KRf3O+d5+NsoGmiZ3w X-ME-Proxy: Feedback-ID: i47b949f6:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 19 Aug 2026 10:52:54 -0400 (EDT) From: Janne Grunau Date: Wed, 19 Aug 2026 16:52:28 +0200 Subject: [PATCH 2/2] iommu: apple-dart: Support specifying the DMA aperture in the DT Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260819-iommu-apple-dart-aperture-v1-2-252703f381aa@jannau.net> References: <20260819-iommu-apple-dart-aperture-v1-0-252703f381aa@jannau.net> In-Reply-To: <20260819-iommu-apple-dart-aperture-v1-0-252703f381aa@jannau.net> To: Sven Peter , Neal Gompa , "Joerg Roedel (AMD)" , Will Deacon , Robin Murphy , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org, iommu@lists.linux.dev, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Janne Grunau , Hector Martin X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=6658; i=j@jannau.net; s=yk2025; h=from:subject:message-id; bh=FbyOzRgdywKDBHRx8l02hzwwB8bqNEhHNRkH6Xxlqxw=; b=owGbwMvMwCW2UNrmdq9+ahrjabUkhqzWw/aP1q+aI81Sy9HyOaRu7pLnCx8tS3LIr2z3C9x04 4fD3GvnOkpZGMS4GGTFFFmStF92MKyuUYypfRAGM4eVCWQIAxenAEzksiHDP4WMrH1Gd6udeSpu PArPniefVd1/zuzJB00GQdXeXt+GLoZ/2ufjXu48u17y8vm71VyfZ4tvWNHuuvzapifcn5vUd70 8xAYA X-Developer-Key: i=j@jannau.net; a=openpgp; fpr=8B336A6BE4E5695E89B8532B81E806F586338419 Apple DARTs are often connected directly to devices that expect only a portion of their address space to be used for DMA (for example, because other ranges are mapped directly to something else). Devices can specify the start and end of the aperture via "iommus" args if the DART device node specifies "#iommu-cells =3D <5>. Aperture start and lengt are 64-bit values since most of the devices use such values. Limit compile testing to 64-bit architectures to avoid warnings when construction 64-bit dma_addr_t values. This range *can* be outside of the DART's IAS. In that case, it is assumed that the hardware truncates addresses and the page tables will only map the lower bits of the address. However, the specified range cannot straddle an IAS boundary (you cannot cover more than IAS worth of address space nor wrap). This corresponds to the vm-base and vm-size properties on the Apple device tree side of things. Co-developed-by: Hector Martin Signed-off-by: Hector Martin Signed-off-by: Janne Grunau --- drivers/iommu/Kconfig | 2 +- drivers/iommu/apple-dart.c | 62 +++++++++++++++++++++++++++++++++++++++---= ---- 2 files changed, 54 insertions(+), 10 deletions(-) diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig index 6e07bd69467a..27954f462582 100644 --- a/drivers/iommu/Kconfig +++ b/drivers/iommu/Kconfig @@ -303,7 +303,7 @@ config SPAPR_TCE_IOMMU =20 config APPLE_DART tristate "Apple DART IOMMU Support" - depends on ARCH_APPLE || COMPILE_TEST + depends on ARCH_APPLE || (COMPILE_TEST && 64BIT) depends on !GENERIC_ATOMIC64 # for IOMMU_IO_PGTABLE_DART select IOMMU_API select IOMMU_IO_PGTABLE_DART diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index b160fb464c5f..16ba65a6b8ff 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -267,6 +268,7 @@ struct apple_dart_domain { struct io_pgtable_ops *pgtbl_ops; =20 bool finalized; + u64 mask; struct mutex init_lock; struct apple_dart_atomic_stream_map stream_maps[MAX_DARTS_PER_DEVICE]; =20 @@ -285,6 +287,13 @@ struct apple_dart_master_cfg { /* Intersection of DART capabilitles */ u32 supports_bypass : 1; =20 + /* + * DMA aperture start and end to be overridden by "iommus"' phandle + * args. By default determined by DART's ias but may be outside of it. + */ + dma_addr_t dma_min; + dma_addr_t dma_max; + struct apple_dart_stream_map stream_maps[MAX_DARTS_PER_DEVICE]; }; =20 @@ -537,7 +546,7 @@ static phys_addr_t apple_dart_iova_to_phys(struct iommu= _domain *domain, if (!ops) return 0; =20 - return ops->iova_to_phys(ops, iova); + return ops->iova_to_phys(ops, iova & dart_domain->mask); } =20 static int apple_dart_map_pages(struct iommu_domain *domain, unsigned long= iova, @@ -551,8 +560,8 @@ static int apple_dart_map_pages(struct iommu_domain *do= main, unsigned long iova, if (!ops) return -ENODEV; =20 - return ops->map_pages(ops, iova, paddr, pgsize, pgcount, prot, gfp, - mapped); + return ops->map_pages(ops, iova & dart_domain->mask, paddr, pgsize, + pgcount, prot, gfp, mapped); } =20 static size_t apple_dart_unmap_pages(struct iommu_domain *domain, @@ -563,7 +572,8 @@ static size_t apple_dart_unmap_pages(struct iommu_domai= n *domain, struct apple_dart_domain *dart_domain =3D to_dart_domain(domain); struct io_pgtable_ops *ops =3D dart_domain->pgtbl_ops; =20 - return ops->unmap_pages(ops, iova, pgsize, pgcount, gather); + return ops->unmap_pages(ops, iova & dart_domain->mask, pgsize, pgcount, + gather); } =20 static void @@ -590,6 +600,7 @@ static int apple_dart_finalize_domain(struct apple_dart= _domain *dart_domain, { struct apple_dart *dart =3D cfg->stream_maps[0].dart; struct io_pgtable_cfg pgtbl_cfg; + u32 ias =3D min_t(u32, dart->ias, fls64(cfg->dma_max)); int ret =3D 0; int i, j; =20 @@ -610,7 +621,7 @@ static int apple_dart_finalize_domain(struct apple_dart= _domain *dart_domain, =20 pgtbl_cfg =3D (struct io_pgtable_cfg){ .pgsize_bitmap =3D dart->pgsize, - .ias =3D dart->ias, + .ias =3D ias, .oas =3D dart->oas, .coherent_walk =3D 1, .iommu_dev =3D dart->dev, @@ -623,10 +634,10 @@ static int apple_dart_finalize_domain(struct apple_da= rt_domain *dart_domain, goto done; } =20 + dart_domain->mask =3D DMA_BIT_MASK(pgtbl_cfg.ias); dart_domain->domain.pgsize_bitmap =3D pgtbl_cfg.pgsize_bitmap; - dart_domain->domain.geometry.aperture_start =3D 0; - dart_domain->domain.geometry.aperture_end =3D - (dma_addr_t)DMA_BIT_MASK(pgtbl_cfg.ias); + dart_domain->domain.geometry.aperture_start =3D cfg->dma_min; + dart_domain->domain.geometry.aperture_end =3D cfg->dma_max; dart_domain->domain.geometry.force_aperture =3D true; =20 dart_domain->finalized =3D true; @@ -803,20 +814,53 @@ static int apple_dart_of_xlate(struct device *dev, struct platform_device *iommu_pdev =3D of_find_device_by_node(args->np); struct apple_dart *dart =3D platform_get_drvdata(iommu_pdev); struct apple_dart *cfg_dart; + dma_addr_t dma_max =3D DMA_BIT_MASK(dart->ias); + dma_addr_t dma_min =3D 0; int i, sid; =20 put_device(&iommu_pdev->dev); =20 - if (args->args_count !=3D 1) + if (args->args_count !=3D 1 && args->args_count !=3D 5) return -EINVAL; + sid =3D args->args[0]; =20 + if (args->args_count =3D=3D 5) { + dma_addr_t length =3D ((dma_addr_t)args->args[3] << 32) | args->args[4]; + + if (!length) + return -EINVAL; + + dma_min =3D ((dma_addr_t)args->args[1] << 32) | args->args[2]; + dma_max =3D dma_min + length - 1; + + /* + * Ensure that the DMA window does not exceed the dart's ias. + */ + if ((dma_min ^ dma_max) & ~DMA_BIT_MASK(dart->ias)) { + dev_err(dev, "Invalid DMA window for ias=3D%d\n", + dart->ias); + return -EINVAL; + } + } + if (!cfg) { cfg =3D kzalloc_obj(*cfg); if (!cfg) return -ENOMEM; /* Will be ANDed with DART capabilities */ cfg->supports_bypass =3D true; + cfg->dma_min =3D dma_min; + cfg->dma_max =3D dma_max; + } else { + if (dma_min >=3D cfg->dma_max || cfg->dma_min >=3D dma_max) { + dev_err(dev, "non-overlapping DMA windows: %pad..%pad, %pad..%pad\n", + &dma_min, &dma_max, + &cfg->dma_min, &cfg->dma_max); + return -EINVAL; + } + cfg->dma_min =3D max(dma_min, cfg->dma_min); + cfg->dma_max =3D min(dma_max, cfg->dma_max); } dev_iommu_priv_set(dev, cfg); =20 --=20 2.55.0