Skip to content

Commit a26be14

Browse files
committed
Merge tag 'iommu-updates-v3.20' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu
Pull IOMMU updates from Joerg Roedel: "This time with: - Generic page-table framework for ARM IOMMUs using the LPAE page-table format, ARM-SMMU and Renesas IPMMU make use of it already. - Break out the IO virtual address allocator from the Intel IOMMU so that it can be used by other DMA-API implementations too. The first user will be the ARM64 common DMA-API implementation for IOMMUs - Device tree support for Renesas IPMMU - Various fixes and cleanups all over the place" * tag 'iommu-updates-v3.20' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu: (36 commits) iommu/amd: Convert non-returned local variable to boolean when relevant iommu: Update my email address iommu/amd: Use wait_event in put_pasid_state_wait iommu/amd: Fix amd_iommu_free_device() iommu/arm-smmu: Avoid build warning iommu/fsl: Various cleanups iommu/fsl: Use %pa to print phys_addr_t iommu/omap: Print phys_addr_t using %pa iommu: Make more drivers depend on COMPILE_TEST iommu/ipmmu-vmsa: Fix IOMMU lookup when multiple IOMMUs are registered iommu: Disable on !MMU builds iommu/fsl: Remove unused fsl_of_pamu_ids[] iommu/fsl: Fix section mismatch iommu/ipmmu-vmsa: Use the ARM LPAE page table allocator iommu: Fix trace_map() to report original iova and original size iommu/arm-smmu: add support for iova_to_phys through ATS1PR iopoll: Introduce memory-mapped IO polling macros iommu/arm-smmu: don't touch the secure STLBIALL register iommu/arm-smmu: make use of generic LPAE allocator iommu: io-pgtable-arm: add non-secure quirk ...
2 parents cdd3054 + a20cc76 commit a26be14

28 files changed

+2239
-1492
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
* Renesas VMSA-Compatible IOMMU
2+
3+
The IPMMU is an IOMMU implementation compatible with the ARM VMSA page tables.
4+
It provides address translation for bus masters outside of the CPU, each
5+
connected to the IPMMU through a port called micro-TLB.
6+
7+
8+
Required Properties:
9+
10+
- compatible: Must contain "renesas,ipmmu-vmsa".
11+
- reg: Base address and size of the IPMMU registers.
12+
- interrupts: Specifiers for the MMU fault interrupts. For instances that
13+
support secure mode two interrupts must be specified, for non-secure and
14+
secure mode, in that order. For instances that don't support secure mode a
15+
single interrupt must be specified.
16+
17+
- #iommu-cells: Must be 1.
18+
19+
Each bus master connected to an IPMMU must reference the IPMMU in its device
20+
node with the following property:
21+
22+
- iommus: A reference to the IPMMU in two cells. The first cell is a phandle
23+
to the IPMMU and the second cell the number of the micro-TLB that the
24+
device is connected to.
25+
26+
27+
Example: R8A7791 IPMMU-MX and VSP1-D0 bus master
28+
29+
ipmmu_mx: mmu@fe951000 {
30+
compatible = "renasas,ipmmu-vmsa";
31+
reg = <0 0xfe951000 0 0x1000>;
32+
interrupts = <0 222 IRQ_TYPE_LEVEL_HIGH>,
33+
<0 221 IRQ_TYPE_LEVEL_HIGH>;
34+
#iommu-cells = <1>;
35+
};
36+
37+
vsp1@fe928000 {
38+
...
39+
iommus = <&ipmmu_mx 13>;
40+
...
41+
};

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,6 +1606,7 @@ M: Will Deacon <[email protected]>
16061606
L: [email protected] (moderated for non-subscribers)
16071607
S: Maintained
16081608
F: drivers/iommu/arm-smmu.c
1609+
F: drivers/iommu/io-pgtable-arm.c
16091610

16101611
ARM64 PORT (AARCH64 ARCHITECTURE)
16111612
M: Catalin Marinas <[email protected]>

arch/arm64/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,6 @@ config ARM64_VA_BITS_42
350350

351351
config ARM64_VA_BITS_48
352352
bool "48-bit"
353-
depends on !ARM_SMMU
354353

355354
endchoice
356355

arch/powerpc/include/asm/fsl_pamu_stash.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ enum pamu_stash_target {
3232
*/
3333

3434
struct pamu_stash_attribute {
35-
u32 cpu; /* cpu number */
36-
u32 cache; /* cache to stash to: L1,L2,L3 */
35+
u32 cpu; /* cpu number */
36+
u32 cache; /* cache to stash to: L1,L2,L3 */
3737
};
3838

3939
#endif /* __FSL_PAMU_STASH_H */

drivers/iommu/Kconfig

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ config IOMMU_API
44

55
menuconfig IOMMU_SUPPORT
66
bool "IOMMU Hardware Support"
7+
depends on MMU
78
default y
89
---help---
910
Say Y here if you want to compile device drivers for IO Memory
@@ -13,13 +14,43 @@ menuconfig IOMMU_SUPPORT
1314

1415
if IOMMU_SUPPORT
1516

17+
menu "Generic IOMMU Pagetable Support"
18+
19+
# Selected by the actual pagetable implementations
20+
config IOMMU_IO_PGTABLE
21+
bool
22+
23+
config IOMMU_IO_PGTABLE_LPAE
24+
bool "ARMv7/v8 Long Descriptor Format"
25+
select IOMMU_IO_PGTABLE
26+
help
27+
Enable support for the ARM long descriptor pagetable format.
28+
This allocator supports 4K/2M/1G, 16K/32M and 64K/512M page
29+
sizes at both stage-1 and stage-2, as well as address spaces
30+
up to 48-bits in size.
31+
32+
config IOMMU_IO_PGTABLE_LPAE_SELFTEST
33+
bool "LPAE selftests"
34+
depends on IOMMU_IO_PGTABLE_LPAE
35+
help
36+
Enable self-tests for LPAE page table allocator. This performs
37+
a series of page-table consistency checks during boot.
38+
39+
If unsure, say N here.
40+
41+
endmenu
42+
43+
config IOMMU_IOVA
44+
bool
45+
1646
config OF_IOMMU
1747
def_bool y
1848
depends on OF && IOMMU_API
1949

2050
config FSL_PAMU
2151
bool "Freescale IOMMU support"
22-
depends on PPC_E500MC
52+
depends on PPC32
53+
depends on PPC_E500MC || COMPILE_TEST
2354
select IOMMU_API
2455
select GENERIC_ALLOCATOR
2556
help
@@ -30,7 +61,8 @@ config FSL_PAMU
3061
# MSM IOMMU support
3162
config MSM_IOMMU
3263
bool "MSM IOMMU Support"
33-
depends on ARCH_MSM8X60 || ARCH_MSM8960
64+
depends on ARM
65+
depends on ARCH_MSM8X60 || ARCH_MSM8960 || COMPILE_TEST
3466
select IOMMU_API
3567
help
3668
Support for the IOMMUs found on certain Qualcomm SOCs.
@@ -91,6 +123,7 @@ config INTEL_IOMMU
91123
bool "Support for Intel IOMMU using DMA Remapping Devices"
92124
depends on PCI_MSI && ACPI && (X86 || IA64_GENERIC)
93125
select IOMMU_API
126+
select IOMMU_IOVA
94127
select DMAR_TABLE
95128
help
96129
DMA remapping (DMAR) devices support enables independent address
@@ -140,7 +173,8 @@ config IRQ_REMAP
140173
# OMAP IOMMU support
141174
config OMAP_IOMMU
142175
bool "OMAP IOMMU Support"
143-
depends on ARCH_OMAP2PLUS
176+
depends on ARM && MMU
177+
depends on ARCH_OMAP2PLUS || COMPILE_TEST
144178
select IOMMU_API
145179

146180
config OMAP_IOMMU_DEBUG
@@ -187,7 +221,7 @@ config TEGRA_IOMMU_SMMU
187221

188222
config EXYNOS_IOMMU
189223
bool "Exynos IOMMU Support"
190-
depends on ARCH_EXYNOS && ARM
224+
depends on ARCH_EXYNOS && ARM && MMU
191225
select IOMMU_API
192226
select ARM_DMA_USE_IOMMU
193227
help
@@ -216,7 +250,7 @@ config SHMOBILE_IPMMU_TLB
216250
config SHMOBILE_IOMMU
217251
bool "IOMMU for Renesas IPMMU/IPMMUI"
218252
default n
219-
depends on ARM
253+
depends on ARM && MMU
220254
depends on ARCH_SHMOBILE || COMPILE_TEST
221255
select IOMMU_API
222256
select ARM_DMA_USE_IOMMU
@@ -287,6 +321,7 @@ config IPMMU_VMSA
287321
depends on ARM_LPAE
288322
depends on ARCH_SHMOBILE || COMPILE_TEST
289323
select IOMMU_API
324+
select IOMMU_IO_PGTABLE_LPAE
290325
select ARM_DMA_USE_IOMMU
291326
help
292327
Support for the Renesas VMSA-compatible IPMMU Renesas found in the
@@ -304,13 +339,13 @@ config SPAPR_TCE_IOMMU
304339

305340
config ARM_SMMU
306341
bool "ARM Ltd. System MMU (SMMU) Support"
307-
depends on ARM64 || (ARM_LPAE && OF)
342+
depends on (ARM64 || ARM) && MMU
308343
select IOMMU_API
344+
select IOMMU_IO_PGTABLE_LPAE
309345
select ARM_DMA_USE_IOMMU if ARM
310346
help
311347
Support for implementations of the ARM System MMU architecture
312-
versions 1 and 2. The driver supports both v7l and v8l table
313-
formats with 4k and 64k page sizes.
348+
versions 1 and 2.
314349

315350
Say Y here if your SoC includes an IOMMU device implementing
316351
the ARM SMMU architecture.

drivers/iommu/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
obj-$(CONFIG_IOMMU_API) += iommu.o
22
obj-$(CONFIG_IOMMU_API) += iommu-traces.o
33
obj-$(CONFIG_IOMMU_API) += iommu-sysfs.o
4+
obj-$(CONFIG_IOMMU_IO_PGTABLE) += io-pgtable.o
5+
obj-$(CONFIG_IOMMU_IO_PGTABLE_LPAE) += io-pgtable-arm.o
6+
obj-$(CONFIG_IOMMU_IOVA) += iova.o
47
obj-$(CONFIG_OF_IOMMU) += of_iommu.o
58
obj-$(CONFIG_MSM_IOMMU) += msm_iommu.o msm_iommu_dev.o
69
obj-$(CONFIG_AMD_IOMMU) += amd_iommu.o amd_iommu_init.o
710
obj-$(CONFIG_AMD_IOMMU_V2) += amd_iommu_v2.o
811
obj-$(CONFIG_ARM_SMMU) += arm-smmu.o
912
obj-$(CONFIG_DMAR_TABLE) += dmar.o
10-
obj-$(CONFIG_INTEL_IOMMU) += iova.o intel-iommu.o
13+
obj-$(CONFIG_INTEL_IOMMU) += intel-iommu.o
1114
obj-$(CONFIG_IPMMU_VMSA) += ipmmu-vmsa.o
1215
obj-$(CONFIG_IRQ_REMAP) += intel_irq_remapping.o irq_remapping.o
1316
obj-$(CONFIG_OMAP_IOMMU) += omap-iommu.o

drivers/iommu/amd_iommu.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (C) 2007-2010 Advanced Micro Devices, Inc.
3-
* Author: Joerg Roedel <[email protected]>
3+
* Author: Joerg Roedel <[email protected]>
44
* Leo Duran <[email protected]>
55
*
66
* This program is free software; you can redistribute it and/or modify it
@@ -843,18 +843,18 @@ static void build_inv_iommu_pages(struct iommu_cmd *cmd, u64 address,
843843
size_t size, u16 domid, int pde)
844844
{
845845
u64 pages;
846-
int s;
846+
bool s;
847847

848848
pages = iommu_num_pages(address, size, PAGE_SIZE);
849-
s = 0;
849+
s = false;
850850

851851
if (pages > 1) {
852852
/*
853853
* If we have to flush more than one page, flush all
854854
* TLB entries for this domain
855855
*/
856856
address = CMD_INV_IOMMU_ALL_PAGES_ADDRESS;
857-
s = 1;
857+
s = true;
858858
}
859859

860860
address &= PAGE_MASK;
@@ -874,18 +874,18 @@ static void build_inv_iotlb_pages(struct iommu_cmd *cmd, u16 devid, int qdep,
874874
u64 address, size_t size)
875875
{
876876
u64 pages;
877-
int s;
877+
bool s;
878878

879879
pages = iommu_num_pages(address, size, PAGE_SIZE);
880-
s = 0;
880+
s = false;
881881

882882
if (pages > 1) {
883883
/*
884884
* If we have to flush more than one page, flush all
885885
* TLB entries for this domain
886886
*/
887887
address = CMD_INV_IOMMU_ALL_PAGES_ADDRESS;
888-
s = 1;
888+
s = true;
889889
}
890890

891891
address &= PAGE_MASK;

drivers/iommu/amd_iommu_init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (C) 2007-2010 Advanced Micro Devices, Inc.
3-
* Author: Joerg Roedel <[email protected]>
3+
* Author: Joerg Roedel <[email protected]>
44
* Leo Duran <[email protected]>
55
*
66
* This program is free software; you can redistribute it and/or modify it

drivers/iommu/amd_iommu_proto.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (C) 2009-2010 Advanced Micro Devices, Inc.
3-
* Author: Joerg Roedel <[email protected]>
3+
* Author: Joerg Roedel <[email protected]>
44
*
55
* This program is free software; you can redistribute it and/or modify it
66
* under the terms of the GNU General Public License version 2 as published

drivers/iommu/amd_iommu_types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (C) 2007-2010 Advanced Micro Devices, Inc.
3-
* Author: Joerg Roedel <[email protected]>
3+
* Author: Joerg Roedel <[email protected]>
44
* Leo Duran <[email protected]>
55
*
66
* This program is free software; you can redistribute it and/or modify it

drivers/iommu/amd_iommu_v2.c

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (C) 2010-2012 Advanced Micro Devices, Inc.
3-
* Author: Joerg Roedel <[email protected]>
3+
* Author: Joerg Roedel <[email protected]>
44
*
55
* This program is free software; you can redistribute it and/or modify it
66
* under the terms of the GNU General Public License version 2 as published
@@ -31,7 +31,7 @@
3131
#include "amd_iommu_proto.h"
3232

3333
MODULE_LICENSE("GPL v2");
34-
MODULE_AUTHOR("Joerg Roedel <[email protected]>");
34+
MODULE_AUTHOR("Joerg Roedel <[email protected]>");
3535

3636
#define MAX_DEVICES 0x10000
3737
#define PRI_QUEUE_SIZE 512
@@ -151,18 +151,6 @@ static void put_device_state(struct device_state *dev_state)
151151
wake_up(&dev_state->wq);
152152
}
153153

154-
static void put_device_state_wait(struct device_state *dev_state)
155-
{
156-
DEFINE_WAIT(wait);
157-
158-
prepare_to_wait(&dev_state->wq, &wait, TASK_UNINTERRUPTIBLE);
159-
if (!atomic_dec_and_test(&dev_state->count))
160-
schedule();
161-
finish_wait(&dev_state->wq, &wait);
162-
163-
free_device_state(dev_state);
164-
}
165-
166154
/* Must be called under dev_state->lock */
167155
static struct pasid_state **__get_pasid_state_ptr(struct device_state *dev_state,
168156
int pasid, bool alloc)
@@ -278,14 +266,7 @@ static void put_pasid_state(struct pasid_state *pasid_state)
278266

279267
static void put_pasid_state_wait(struct pasid_state *pasid_state)
280268
{
281-
DEFINE_WAIT(wait);
282-
283-
prepare_to_wait(&pasid_state->wq, &wait, TASK_UNINTERRUPTIBLE);
284-
285-
if (!atomic_dec_and_test(&pasid_state->count))
286-
schedule();
287-
288-
finish_wait(&pasid_state->wq, &wait);
269+
wait_event(pasid_state->wq, !atomic_read(&pasid_state->count));
289270
free_pasid_state(pasid_state);
290271
}
291272

@@ -851,7 +832,13 @@ void amd_iommu_free_device(struct pci_dev *pdev)
851832
/* Get rid of any remaining pasid states */
852833
free_pasid_states(dev_state);
853834

854-
put_device_state_wait(dev_state);
835+
put_device_state(dev_state);
836+
/*
837+
* Wait until the last reference is dropped before freeing
838+
* the device state.
839+
*/
840+
wait_event(dev_state->wq, !atomic_read(&dev_state->count));
841+
free_device_state(dev_state);
855842
}
856843
EXPORT_SYMBOL(amd_iommu_free_device);
857844

@@ -921,7 +908,7 @@ static int __init amd_iommu_v2_init(void)
921908
{
922909
int ret;
923910

924-
pr_info("AMD IOMMUv2 driver by Joerg Roedel <[email protected]>\n");
911+
pr_info("AMD IOMMUv2 driver by Joerg Roedel <[email protected]>\n");
925912

926913
if (!amd_iommu_v2_supported()) {
927914
pr_info("AMD IOMMUv2 functionality not available on this system\n");

0 commit comments

Comments
 (0)