x86/mm, mm/hwpoison: Don't unconditionally unmap kernel 1:1 pages
[sfrench/cifs-2.6.git] / include / linux / dma-mapping.h
index 81ed9b2d84dcc78e1b2213e9a22efd0f4f384330..34fe8463d10ea3be5df5fb27d80c51d663b94136 100644 (file)
@@ -136,7 +136,7 @@ struct dma_map_ops {
        int is_phys;
 };
 
-extern const struct dma_map_ops dma_noop_ops;
+extern const struct dma_map_ops dma_direct_ops;
 extern const struct dma_map_ops dma_virt_ops;
 
 #define DMA_BIT_MASK(n)        (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
@@ -513,10 +513,18 @@ static inline void *dma_alloc_attrs(struct device *dev, size_t size,
        void *cpu_addr;
 
        BUG_ON(!ops);
+       WARN_ON_ONCE(dev && !dev->coherent_dma_mask);
 
        if (dma_alloc_from_dev_coherent(dev, size, dma_handle, &cpu_addr))
                return cpu_addr;
 
+       /*
+        * Let the implementation decide on the zone to allocate from, and
+        * decide on the way of zeroing the memory given that the memory
+        * returned should always be zeroed.
+        */
+       flag &= ~(__GFP_DMA | __GFP_DMA32 | __GFP_HIGHMEM | __GFP_ZERO);
+
        if (!arch_dma_alloc_attrs(&dev, &flag))
                return NULL;
        if (!ops->alloc)
@@ -568,6 +576,14 @@ static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
        return 0;
 }
 
+/*
+ * This is a hack for the legacy x86 forbid_dac and iommu_sac_force. Please
+ * don't use this is new code.
+ */
+#ifndef arch_dma_supported
+#define arch_dma_supported(dev, mask)  (1)
+#endif
+
 static inline void dma_check_mask(struct device *dev, u64 mask)
 {
        if (sme_active() && (mask < (((u64)sme_get_me_mask() << 1) - 1)))
@@ -580,6 +596,9 @@ static inline int dma_supported(struct device *dev, u64 mask)
 
        if (!ops)
                return 0;
+       if (!arch_dma_supported(dev, mask))
+               return 0;
+
        if (!ops->dma_supported)
                return 1;
        return ops->dma_supported(dev, mask);
@@ -692,7 +711,7 @@ static inline int dma_set_seg_boundary(struct device *dev, unsigned long mask)
 #ifndef dma_max_pfn
 static inline unsigned long dma_max_pfn(struct device *dev)
 {
-       return *dev->dma_mask >> PAGE_SHIFT;
+       return (*dev->dma_mask >> PAGE_SHIFT) + dev->dma_pfn_offset;
 }
 #endif