Skip to content

Commit ae3325f

Browse files
committed
Merge branches 'arm/smmu', 'mediatek', 's390', 'ti/omap', 'riscv' and 'core' into next
7 parents 2d5404c + 9af48bb + 3ab21ad + ecda483 + 95b6235 + 488ffbf + fcdb982 commit ae3325f

File tree

34 files changed

+3333
-470
lines changed

34 files changed

+3333
-470
lines changed

Documentation/devicetree/bindings/iommu/arm,smmu.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ properties:
3636
items:
3737
- enum:
3838
- qcom,qcm2290-smmu-500
39+
- qcom,qcs615-smmu-500
3940
- qcom,qcs8300-smmu-500
4041
- qcom,qdu1000-smmu-500
4142
- qcom,sa8255p-smmu-500
4243
- qcom,sa8775p-smmu-500
44+
- qcom,sar2130p-smmu-500
4345
- qcom,sc7180-smmu-500
4446
- qcom,sc7280-smmu-500
4547
- qcom,sc8180x-smmu-500
@@ -88,6 +90,7 @@ properties:
8890
- qcom,qcm2290-smmu-500
8991
- qcom,sa8255p-smmu-500
9092
- qcom,sa8775p-smmu-500
93+
- qcom,sar2130p-smmu-500
9194
- qcom,sc7280-smmu-500
9295
- qcom,sc8180x-smmu-500
9396
- qcom,sc8280xp-smmu-500
@@ -524,6 +527,7 @@ allOf:
524527
compatible:
525528
items:
526529
- enum:
530+
- qcom,sar2130p-smmu-500
527531
- qcom,sm8550-smmu-500
528532
- qcom,sm8650-smmu-500
529533
- qcom,x1e80100-smmu-500
@@ -555,6 +559,7 @@ allOf:
555559
- cavium,smmu-v2
556560
- marvell,ap806-smmu-500
557561
- nvidia,smmu-500
562+
- qcom,qcs615-smmu-500
558563
- qcom,qcs8300-smmu-500
559564
- qcom,qdu1000-smmu-500
560565
- qcom,sa8255p-smmu-500
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
2+
%YAML 1.2
3+
---
4+
$id: http://devicetree.org/schemas/iommu/riscv,iommu.yaml#
5+
$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+
title: RISC-V IOMMU Architecture Implementation
8+
9+
maintainers:
10+
- Tomasz Jeznach <[email protected]>
11+
12+
description: |
13+
The RISC-V IOMMU provides memory address translation and isolation for
14+
input and output devices, supporting per-device translation context,
15+
shared process address spaces including the ATS and PRI components of
16+
the PCIe specification, two stage address translation and MSI remapping.
17+
It supports identical translation table format to the RISC-V address
18+
translation tables with page level access and protection attributes.
19+
Hardware uses in-memory command and fault reporting queues with wired
20+
interrupt or MSI notifications.
21+
22+
Visit https://github.com/riscv-non-isa/riscv-iommu for more details.
23+
24+
For information on assigning RISC-V IOMMU to its peripheral devices,
25+
see generic IOMMU bindings.
26+
27+
properties:
28+
# For PCIe IOMMU hardware compatible property should contain the vendor
29+
# and device ID according to the PCI Bus Binding specification.
30+
# Since PCI provides built-in identification methods, compatible is not
31+
# actually required. For non-PCIe hardware implementations 'riscv,iommu'
32+
# should be specified along with 'reg' property providing MMIO location.
33+
compatible:
34+
oneOf:
35+
- items:
36+
- enum:
37+
- qemu,riscv-iommu
38+
- const: riscv,iommu
39+
- items:
40+
- enum:
41+
- pci1efd,edf1
42+
- const: riscv,pci-iommu
43+
44+
reg:
45+
maxItems: 1
46+
description:
47+
For non-PCI devices this represents base address and size of for the
48+
IOMMU memory mapped registers interface.
49+
For PCI IOMMU hardware implementation this should represent an address
50+
of the IOMMU, as defined in the PCI Bus Binding reference.
51+
52+
'#iommu-cells':
53+
const: 1
54+
description:
55+
The single cell describes the requester id emitted by a master to the
56+
IOMMU.
57+
58+
interrupts:
59+
minItems: 1
60+
maxItems: 4
61+
description:
62+
Wired interrupt vectors available for RISC-V IOMMU to notify the
63+
RISC-V HARTS. The cause to interrupt vector is software defined
64+
using IVEC IOMMU register.
65+
66+
msi-parent: true
67+
68+
power-domains:
69+
maxItems: 1
70+
71+
required:
72+
- compatible
73+
- reg
74+
- '#iommu-cells'
75+
76+
additionalProperties: false
77+
78+
examples:
79+
- |+
80+
/* Example 1 (IOMMU device with wired interrupts) */
81+
#include <dt-bindings/interrupt-controller/irq.h>
82+
83+
iommu1: iommu@1bccd000 {
84+
compatible = "qemu,riscv-iommu", "riscv,iommu";
85+
reg = <0x1bccd000 0x1000>;
86+
interrupt-parent = <&aplic_smode>;
87+
interrupts = <32 IRQ_TYPE_LEVEL_HIGH>,
88+
<33 IRQ_TYPE_LEVEL_HIGH>,
89+
<34 IRQ_TYPE_LEVEL_HIGH>,
90+
<35 IRQ_TYPE_LEVEL_HIGH>;
91+
#iommu-cells = <1>;
92+
};
93+
94+
/* Device with two IOMMU device IDs, 0 and 7 */
95+
master1 {
96+
iommus = <&iommu1 0>, <&iommu1 7>;
97+
};
98+
99+
- |+
100+
/* Example 2 (IOMMU device with shared wired interrupt) */
101+
#include <dt-bindings/interrupt-controller/irq.h>
102+
103+
iommu2: iommu@1bccd000 {
104+
compatible = "qemu,riscv-iommu", "riscv,iommu";
105+
reg = <0x1bccd000 0x1000>;
106+
interrupt-parent = <&aplic_smode>;
107+
interrupts = <32 IRQ_TYPE_LEVEL_HIGH>;
108+
#iommu-cells = <1>;
109+
};
110+
111+
- |+
112+
/* Example 3 (IOMMU device with MSIs) */
113+
iommu3: iommu@1bcdd000 {
114+
compatible = "qemu,riscv-iommu", "riscv,iommu";
115+
reg = <0x1bccd000 0x1000>;
116+
msi-parent = <&imsics_smode>;
117+
#iommu-cells = <1>;
118+
};
119+
120+
- |+
121+
/* Example 4 (IOMMU PCIe device with MSIs) */
122+
bus {
123+
#address-cells = <2>;
124+
#size-cells = <2>;
125+
126+
pcie@30000000 {
127+
device_type = "pci";
128+
#address-cells = <3>;
129+
#size-cells = <2>;
130+
reg = <0x0 0x30000000 0x0 0x1000000>;
131+
ranges = <0x02000000 0x0 0x41000000 0x0 0x41000000 0x0 0x0f000000>;
132+
133+
/*
134+
* The IOMMU manages all functions in this PCI domain except
135+
* itself. Omit BDF 00:01.0.
136+
*/
137+
iommu-map = <0x0 &iommu0 0x0 0x8>,
138+
<0x9 &iommu0 0x9 0xfff7>;
139+
140+
/* The IOMMU programming interface uses slot 00:01.0 */
141+
iommu0: iommu@1,0 {
142+
compatible = "pci1efd,edf1", "riscv,pci-iommu";
143+
reg = <0x800 0 0 0 0>;
144+
#iommu-cells = <1>;
145+
};
146+
};
147+
};

MAINTAINERS

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19810,6 +19810,15 @@ F: arch/riscv/
1981019810
N: riscv
1981119811
K: riscv
1981219812

19813+
RISC-V IOMMU
19814+
M: Tomasz Jeznach <[email protected]>
19815+
19816+
19817+
S: Maintained
19818+
T: git git://git.kernel.org/pub/scm/linux/kernel/git/iommu/linux.git
19819+
F: Documentation/devicetree/bindings/iommu/riscv,iommu.yaml
19820+
F: drivers/iommu/riscv/
19821+
1981319822
RISC-V MICROCHIP FPGA SUPPORT
1981419823
M: Conor Dooley <[email protected]>
1981519824
M: Daire McNamara <[email protected]>

arch/s390/include/asm/pci.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ struct zpci_bar_struct {
9696
u8 size; /* order 2 exponent */
9797
};
9898

99-
struct s390_domain;
10099
struct kvm_zdev;
101100

102101
#define ZPCI_FUNCTIONS_PER_BUS 256
@@ -181,9 +180,10 @@ struct zpci_dev {
181180
struct dentry *debugfs_dev;
182181

183182
/* IOMMU and passthrough */
184-
struct s390_domain *s390_domain; /* s390 IOMMU domain data */
183+
struct iommu_domain *s390_domain; /* attached IOMMU domain */
185184
struct kvm_zdev *kzdev;
186185
struct mutex kzdev_lock;
186+
spinlock_t dom_lock; /* protect s390_domain change */
187187
};
188188

189189
static inline bool zdev_enabled(struct zpci_dev *zdev)

arch/s390/pci/pci.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ int zpci_fmb_enable_device(struct zpci_dev *zdev)
160160
u64 req = ZPCI_CREATE_REQ(zdev->fh, 0, ZPCI_MOD_FC_SET_MEASURE);
161161
struct zpci_iommu_ctrs *ctrs;
162162
struct zpci_fib fib = {0};
163+
unsigned long flags;
163164
u8 cc, status;
164165

165166
if (zdev->fmb || sizeof(*zdev->fmb) < zdev->fmb_length)
@@ -171,6 +172,7 @@ int zpci_fmb_enable_device(struct zpci_dev *zdev)
171172
WARN_ON((u64) zdev->fmb & 0xf);
172173

173174
/* reset software counters */
175+
spin_lock_irqsave(&zdev->dom_lock, flags);
174176
ctrs = zpci_get_iommu_ctrs(zdev);
175177
if (ctrs) {
176178
atomic64_set(&ctrs->mapped_pages, 0);
@@ -179,6 +181,7 @@ int zpci_fmb_enable_device(struct zpci_dev *zdev)
179181
atomic64_set(&ctrs->sync_map_rpcits, 0);
180182
atomic64_set(&ctrs->sync_rpcits, 0);
181183
}
184+
spin_unlock_irqrestore(&zdev->dom_lock, flags);
182185

183186

184187
fib.fmb_addr = virt_to_phys(zdev->fmb);

arch/s390/pci/pci_debug.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,23 @@ static void pci_fmb_show(struct seq_file *m, char *name[], int length,
7171

7272
static void pci_sw_counter_show(struct seq_file *m)
7373
{
74-
struct zpci_iommu_ctrs *ctrs = zpci_get_iommu_ctrs(m->private);
74+
struct zpci_dev *zdev = m->private;
75+
struct zpci_iommu_ctrs *ctrs;
7576
atomic64_t *counter;
77+
unsigned long flags;
7678
int i;
7779

80+
spin_lock_irqsave(&zdev->dom_lock, flags);
81+
ctrs = zpci_get_iommu_ctrs(m->private);
7882
if (!ctrs)
79-
return;
83+
goto unlock;
8084

8185
counter = &ctrs->mapped_pages;
8286
for (i = 0; i < ARRAY_SIZE(pci_sw_names); i++, counter++)
8387
seq_printf(m, "%26s:\t%llu\n", pci_sw_names[i],
8488
atomic64_read(counter));
89+
unlock:
90+
spin_unlock_irqrestore(&zdev->dom_lock, flags);
8591
}
8692

8793
static int pci_perf_show(struct seq_file *m, void *v)

drivers/gpu/drm/nouveau/nvkm/engine/device/tegra.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ nvkm_device_tegra_probe_iommu(struct nvkm_device_tegra *tdev)
120120
mutex_init(&tdev->iommu.mutex);
121121

122122
if (device_iommu_mapped(dev)) {
123-
tdev->iommu.domain = iommu_domain_alloc(&platform_bus_type);
124-
if (!tdev->iommu.domain)
123+
tdev->iommu.domain = iommu_paging_domain_alloc(dev);
124+
if (IS_ERR(tdev->iommu.domain))
125125
goto error;
126126

127127
/*

drivers/iommu/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ config MSM_IOMMU
195195
source "drivers/iommu/amd/Kconfig"
196196
source "drivers/iommu/intel/Kconfig"
197197
source "drivers/iommu/iommufd/Kconfig"
198+
source "drivers/iommu/riscv/Kconfig"
198199

199200
config IRQ_REMAP
200201
bool "Support for Interrupt Remapping"

drivers/iommu/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# SPDX-License-Identifier: GPL-2.0
2-
obj-y += amd/ intel/ arm/ iommufd/
2+
obj-y += amd/ intel/ arm/ iommufd/ riscv/
33
obj-$(CONFIG_IOMMU_API) += iommu.o
44
obj-$(CONFIG_IOMMU_API) += iommu-traces.o
55
obj-$(CONFIG_IOMMU_API) += iommu-sysfs.o

drivers/iommu/amd/amd_iommu.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ extern int amd_iommu_gpt_level;
4646
extern unsigned long amd_iommu_pgsize_bitmap;
4747

4848
/* Protection domain ops */
49+
void amd_iommu_init_identity_domain(void);
4950
struct protection_domain *protection_domain_alloc(unsigned int type, int nid);
5051
void protection_domain_free(struct protection_domain *domain);
5152
struct iommu_domain *amd_iommu_domain_alloc_sva(struct device *dev,
@@ -118,9 +119,14 @@ static inline bool check_feature2(u64 mask)
118119
return (amd_iommu_efr2 & mask);
119120
}
120121

122+
static inline bool amd_iommu_v2_pgtbl_supported(void)
123+
{
124+
return (check_feature(FEATURE_GIOSUP) && check_feature(FEATURE_GT));
125+
}
126+
121127
static inline bool amd_iommu_gt_ppr_supported(void)
122128
{
123-
return (check_feature(FEATURE_GT) &&
129+
return (amd_iommu_v2_pgtbl_supported() &&
124130
check_feature(FEATURE_PPR) &&
125131
check_feature(FEATURE_EPHSUP));
126132
}

drivers/iommu/amd/init.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2070,14 +2070,6 @@ static int __init iommu_init_pci(struct amd_iommu *iommu)
20702070

20712071
init_iommu_perf_ctr(iommu);
20722072

2073-
if (amd_iommu_pgtable == AMD_IOMMU_V2) {
2074-
if (!check_feature(FEATURE_GIOSUP) ||
2075-
!check_feature(FEATURE_GT)) {
2076-
pr_warn("Cannot enable v2 page table for DMA-API. Fallback to v1.\n");
2077-
amd_iommu_pgtable = AMD_IOMMU_V1;
2078-
}
2079-
}
2080-
20812073
if (is_rd890_iommu(iommu->dev)) {
20822074
int i, j;
20832075

@@ -2172,6 +2164,9 @@ static int __init amd_iommu_init_pci(void)
21722164
struct amd_iommu_pci_seg *pci_seg;
21732165
int ret;
21742166

2167+
/* Init global identity domain before registering IOMMU */
2168+
amd_iommu_init_identity_domain();
2169+
21752170
for_each_iommu(iommu) {
21762171
ret = iommu_init_pci(iommu);
21772172
if (ret) {
@@ -3091,6 +3086,13 @@ static int __init early_amd_iommu_init(void)
30913086
FIELD_GET(FEATURE_GATS, amd_iommu_efr) == GUEST_PGTABLE_5_LEVEL)
30923087
amd_iommu_gpt_level = PAGE_MODE_5_LEVEL;
30933088

3089+
if (amd_iommu_pgtable == AMD_IOMMU_V2) {
3090+
if (!amd_iommu_v2_pgtbl_supported()) {
3091+
pr_warn("Cannot enable v2 page table for DMA-API. Fallback to v1.\n");
3092+
amd_iommu_pgtable = AMD_IOMMU_V1;
3093+
}
3094+
}
3095+
30943096
/* Disable any previously enabled IOMMUs */
30953097
if (!is_kdump_kernel() || amd_iommu_disabled)
30963098
disable_iommus();

0 commit comments

Comments
 (0)