| .. | .. |
|---|
| 1 | 1 | // SPDX-License-Identifier: GPL-2.0 |
|---|
| 2 | +#include <linux/dma-map-ops.h> |
|---|
| 2 | 3 | #include <linux/dma-direct.h> |
|---|
| 3 | | -#include <linux/dma-debug.h> |
|---|
| 4 | +#include <linux/iommu.h> |
|---|
| 4 | 5 | #include <linux/dmar.h> |
|---|
| 5 | 6 | #include <linux/export.h> |
|---|
| 6 | | -#include <linux/bootmem.h> |
|---|
| 7 | +#include <linux/memblock.h> |
|---|
| 7 | 8 | #include <linux/gfp.h> |
|---|
| 8 | 9 | #include <linux/pci.h> |
|---|
| 9 | 10 | |
|---|
| .. | .. |
|---|
| 11 | 12 | #include <asm/dma.h> |
|---|
| 12 | 13 | #include <asm/iommu.h> |
|---|
| 13 | 14 | #include <asm/gart.h> |
|---|
| 14 | | -#include <asm/calgary.h> |
|---|
| 15 | 15 | #include <asm/x86_init.h> |
|---|
| 16 | 16 | #include <asm/iommu_table.h> |
|---|
| 17 | 17 | |
|---|
| 18 | 18 | static bool disable_dac_quirk __read_mostly; |
|---|
| 19 | 19 | |
|---|
| 20 | | -const struct dma_map_ops *dma_ops = &dma_direct_ops; |
|---|
| 20 | +const struct dma_map_ops *dma_ops; |
|---|
| 21 | 21 | EXPORT_SYMBOL(dma_ops); |
|---|
| 22 | 22 | |
|---|
| 23 | 23 | #ifdef CONFIG_IOMMU_DEBUG |
|---|
| .. | .. |
|---|
| 34 | 34 | /* Set this to 1 if there is a HW IOMMU in the system */ |
|---|
| 35 | 35 | int iommu_detected __read_mostly = 0; |
|---|
| 36 | 36 | |
|---|
| 37 | | -/* |
|---|
| 38 | | - * This variable becomes 1 if iommu=pt is passed on the kernel command line. |
|---|
| 39 | | - * If this variable is 1, IOMMU implementations do no DMA translation for |
|---|
| 40 | | - * devices and allow every device to access to whole physical memory. This is |
|---|
| 41 | | - * useful if a user wants to use an IOMMU only for KVM device assignment to |
|---|
| 42 | | - * guests and not for driver dma translation. |
|---|
| 43 | | - * It is also possible to disable by default in kernel config, and enable with |
|---|
| 44 | | - * iommu=nopt at boot time. |
|---|
| 45 | | - */ |
|---|
| 46 | | -#ifdef CONFIG_IOMMU_DEFAULT_PASSTHROUGH |
|---|
| 47 | | -int iommu_pass_through __read_mostly = 1; |
|---|
| 48 | | -#else |
|---|
| 49 | | -int iommu_pass_through __read_mostly; |
|---|
| 50 | | -#endif |
|---|
| 51 | | - |
|---|
| 52 | 37 | extern struct iommu_table_entry __iommu_table[], __iommu_table_end[]; |
|---|
| 53 | | - |
|---|
| 54 | | -/* Dummy device used for NULL arguments (normally ISA). */ |
|---|
| 55 | | -struct device x86_dma_fallback_dev = { |
|---|
| 56 | | - .init_name = "fallback device", |
|---|
| 57 | | - .coherent_dma_mask = ISA_DMA_BIT_MASK, |
|---|
| 58 | | - .dma_mask = &x86_dma_fallback_dev.coherent_dma_mask, |
|---|
| 59 | | -}; |
|---|
| 60 | | -EXPORT_SYMBOL(x86_dma_fallback_dev); |
|---|
| 61 | 38 | |
|---|
| 62 | 39 | void __init pci_iommu_alloc(void) |
|---|
| 63 | 40 | { |
|---|
| .. | .. |
|---|
| 77 | 54 | } |
|---|
| 78 | 55 | } |
|---|
| 79 | 56 | |
|---|
| 80 | | -bool arch_dma_alloc_attrs(struct device **dev) |
|---|
| 81 | | -{ |
|---|
| 82 | | - if (!*dev) |
|---|
| 83 | | - *dev = &x86_dma_fallback_dev; |
|---|
| 84 | | - |
|---|
| 85 | | - if (!is_device_dma_capable(*dev)) |
|---|
| 86 | | - return false; |
|---|
| 87 | | - return true; |
|---|
| 88 | | - |
|---|
| 89 | | -} |
|---|
| 90 | | -EXPORT_SYMBOL(arch_dma_alloc_attrs); |
|---|
| 91 | | - |
|---|
| 92 | 57 | /* |
|---|
| 93 | | - * See <Documentation/x86/x86_64/boot-options.txt> for the iommu kernel |
|---|
| 58 | + * See <Documentation/x86/x86_64/boot-options.rst> for the iommu kernel |
|---|
| 94 | 59 | * parameter documentation. |
|---|
| 95 | 60 | */ |
|---|
| 96 | 61 | static __init int iommu_setup(char *p) |
|---|
| .. | .. |
|---|
| 140 | 105 | swiotlb = 1; |
|---|
| 141 | 106 | #endif |
|---|
| 142 | 107 | if (!strncmp(p, "pt", 2)) |
|---|
| 143 | | - iommu_pass_through = 1; |
|---|
| 108 | + iommu_set_default_passthrough(true); |
|---|
| 144 | 109 | if (!strncmp(p, "nopt", 4)) |
|---|
| 145 | | - iommu_pass_through = 0; |
|---|
| 110 | + iommu_set_default_translated(true); |
|---|
| 146 | 111 | |
|---|
| 147 | 112 | gart_parse_options(p); |
|---|
| 148 | | - |
|---|
| 149 | | -#ifdef CONFIG_CALGARY_IOMMU |
|---|
| 150 | | - if (!strncmp(p, "calgary", 7)) |
|---|
| 151 | | - use_calgary = 1; |
|---|
| 152 | | -#endif /* CONFIG_CALGARY_IOMMU */ |
|---|
| 153 | 113 | |
|---|
| 154 | 114 | p += strcspn(p, ","); |
|---|
| 155 | 115 | if (*p == ',') |
|---|
| .. | .. |
|---|
| 180 | 140 | |
|---|
| 181 | 141 | static int via_no_dac_cb(struct pci_dev *pdev, void *data) |
|---|
| 182 | 142 | { |
|---|
| 183 | | - pdev->dev.bus_dma_mask = DMA_BIT_MASK(32); |
|---|
| 143 | + pdev->dev.bus_dma_limit = DMA_BIT_MASK(32); |
|---|
| 184 | 144 | return 0; |
|---|
| 185 | 145 | } |
|---|
| 186 | 146 | |
|---|