]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
x86, swiotlb: Simplify SWIOTLB pci_swiotlb_detect routine.
authorKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Thu, 26 Aug 2010 17:57:59 +0000 (13:57 -0400)
committerH. Peter Anvin <hpa@linux.intel.com>
Thu, 26 Aug 2010 22:13:29 +0000 (15:13 -0700)
In 'pci_swiotlb_detect' we used to do two different things:
 a). If user provided 'iommu=soft' or 'swiotlb=force' we
     would set swiotlb=1 and return 1 (and forcing pci-dma.c
     to call pci_swiotlb_init() immediately).
 b). If 4GB or more would be detected and if user did not specify
     iommu=off, we would set 'swiotlb=1' and return whatever 'a)'
     figured out.

We simplify this by splitting a) and b) in two different routines.

CC: Fujita Tomonori <fujita.tomonori@lab.ntt.co.jp>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
LKML-Reference: <1282845485-8991-5-git-send-email-konrad.wilk@oracle.com>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
arch/x86/include/asm/iommu_table.h
arch/x86/include/asm/swiotlb.h
arch/x86/kernel/pci-dma.c
arch/x86/kernel/pci-swiotlb.c

index 2124e3ef6f9804e215e77873f6a16b7db678daa9..df55a78888e30da485d345dc42cd344c4d115f4a 100644 (file)
@@ -64,10 +64,10 @@ struct iommu_table_entry {
  * to stop detecting the other IOMMUs after yours has been detected.
  */
 #define IOMMU_INIT_POST(_detect)                                       \
-       __IOMMU_INIT(_detect, pci_swiotlb_detect,  0, 0, 0)
+       __IOMMU_INIT(_detect, pci_swiotlb_detect_4gb,  0, 0, 0)
 
 #define IOMMU_INIT_POST_FINISH(detect)                                 \
-       __IOMMU_INIT(_detect, pci_swiotlb_detect,  0, 0, 1)
+       __IOMMU_INIT(_detect, pci_swiotlb_detect_4gb,  0, 0, 1)
 
 /*
  * A more sophisticated version of IOMMU_INIT. This variant requires:
index 8085277e1b8b62747f8d8e57dc1ce16d91214e8c..977f1761a25d51b25737d84436a3a80dd3f60810 100644 (file)
@@ -5,17 +5,26 @@
 
 #ifdef CONFIG_SWIOTLB
 extern int swiotlb;
-extern int __init pci_swiotlb_detect(void);
+extern int __init pci_swiotlb_detect_override(void);
+extern int __init pci_swiotlb_detect_4gb(void);
 extern void __init pci_swiotlb_init(void);
+extern void __init pci_swiotlb_late_init(void);
 #else
 #define swiotlb 0
-static inline int pci_swiotlb_detect(void)
+static inline int pci_swiotlb_detect_override(void)
+{
+       return 0;
+}
+static inline int pci_swiotlb_detect_4gb(void)
 {
        return 0;
 }
 static inline void pci_swiotlb_init(void)
 {
 }
+static inline void pci_swiotlb_late_init(void)
+{
+}
 #endif
 
 static inline void dma_mark_clean(void *addr, size_t size) {}
index 9f07cfcbd3a5e60db651c952c9a66fa21dd68d87..1b3beb5075e651813e9122a4bb5cc470b7659014 100644 (file)
@@ -133,9 +133,11 @@ void __init pci_iommu_alloc(void)
        /* free the range so iommu could get some range less than 4G */
        dma32_free_bootmem();
 
-       if (pci_xen_swiotlb_detect() || pci_swiotlb_detect())
+       if (pci_xen_swiotlb_detect() || pci_swiotlb_detect_override())
                goto out;
 
+       pci_swiotlb_detect_4gb();
+
        gart_iommu_hole_init();
 
        detect_calgary();
index a5bc528d43282a344936922328d2b5bf59b187ae..c7a72faeb1466b60a05c2c83eda997404858f6a3 100644 (file)
@@ -41,24 +41,33 @@ static struct dma_map_ops swiotlb_dma_ops = {
 };
 
 /*
- * pci_swiotlb_detect - set swiotlb to 1 if necessary
+ * pci_swiotlb_detect_override - set swiotlb to 1 if necessary
  *
  * This returns non-zero if we are forced to use swiotlb (by the boot
  * option).
  */
-int __init pci_swiotlb_detect(void)
+int __init pci_swiotlb_detect_override(void)
 {
        int use_swiotlb = swiotlb | swiotlb_force;
 
+       if (swiotlb_force)
+               swiotlb = 1;
+
+       return use_swiotlb;
+}
+
+/*
+ * if 4GB or more detected (and iommu=off not set) return 1
+ * and set swiotlb to 1.
+ */
+int __init pci_swiotlb_detect_4gb(void)
+{
        /* don't initialize swiotlb if iommu=off (no_iommu=1) */
 #ifdef CONFIG_X86_64
        if (!no_iommu && max_pfn > MAX_DMA32_PFN)
                swiotlb = 1;
 #endif
-       if (swiotlb_force)
-               swiotlb = 1;
-
-       return use_swiotlb;
+       return swiotlb;
 }
 
 void __init pci_swiotlb_init(void)
@@ -68,3 +77,15 @@ void __init pci_swiotlb_init(void)
                dma_ops = &swiotlb_dma_ops;
        }
 }
+
+void __init pci_swiotlb_late_init(void)
+{
+       /* An IOMMU turned us off. */
+       if (!swiotlb)
+               swiotlb_free();
+       else {
+               printk(KERN_INFO "PCI-DMA: "
+                      "Using software bounce buffering for IO (SWIOTLB)\n");
+               swiotlb_print_info();
+       }
+}