Merge tag 'dma-mapping-5.20-2022-08-06' of git://git.infradead.org/users/hch/dma...
[linux-2.6-microblaze.git] / include / linux / dma-map-ops.h
index 0d5b06b..010df04 100644 (file)
 
 struct cma;
 
+/*
+ * Values for struct dma_map_ops.flags:
+ *
+ * DMA_F_PCI_P2PDMA_SUPPORTED: Indicates the dma_map_ops implementation can
+ * handle PCI P2PDMA pages in the map_sg/unmap_sg operation.
+ */
+#define DMA_F_PCI_P2PDMA_SUPPORTED     (1 << 0)
+
 struct dma_map_ops {
+       unsigned int flags;
+
        void *(*alloc)(struct device *dev, size_t size,
                        dma_addr_t *dma_handle, gfp_t gfp,
                        unsigned long attrs);
@@ -69,6 +79,7 @@ struct dma_map_ops {
        int (*dma_supported)(struct device *dev, u64 mask);
        u64 (*get_required_mask)(struct device *dev);
        size_t (*max_mapping_size)(struct device *dev);
+       size_t (*opt_mapping_size)(void);
        unsigned long (*get_merge_boundary)(struct device *dev);
 };
 
@@ -379,4 +390,57 @@ static inline void debug_dma_dump_mappings(struct device *dev)
 
 extern const struct dma_map_ops dma_dummy_ops;
 
+enum pci_p2pdma_map_type {
+       /*
+        * PCI_P2PDMA_MAP_UNKNOWN: Used internally for indicating the mapping
+        * type hasn't been calculated yet. Functions that return this enum
+        * never return this value.
+        */
+       PCI_P2PDMA_MAP_UNKNOWN = 0,
+
+       /*
+        * PCI_P2PDMA_MAP_NOT_SUPPORTED: Indicates the transaction will
+        * traverse the host bridge and the host bridge is not in the
+        * allowlist. DMA Mapping routines should return an error when
+        * this is returned.
+        */
+       PCI_P2PDMA_MAP_NOT_SUPPORTED,
+
+       /*
+        * PCI_P2PDMA_BUS_ADDR: Indicates that two devices can talk to
+        * each other directly through a PCI switch and the transaction will
+        * not traverse the host bridge. Such a mapping should program
+        * the DMA engine with PCI bus addresses.
+        */
+       PCI_P2PDMA_MAP_BUS_ADDR,
+
+       /*
+        * PCI_P2PDMA_MAP_THRU_HOST_BRIDGE: Indicates two devices can talk
+        * to each other, but the transaction traverses a host bridge on the
+        * allowlist. In this case, a normal mapping either with CPU physical
+        * addresses (in the case of dma-direct) or IOVA addresses (in the
+        * case of IOMMUs) should be used to program the DMA engine.
+        */
+       PCI_P2PDMA_MAP_THRU_HOST_BRIDGE,
+};
+
+struct pci_p2pdma_map_state {
+       struct dev_pagemap *pgmap;
+       int map;
+       u64 bus_off;
+};
+
+#ifdef CONFIG_PCI_P2PDMA
+enum pci_p2pdma_map_type
+pci_p2pdma_map_segment(struct pci_p2pdma_map_state *state, struct device *dev,
+                      struct scatterlist *sg);
+#else /* CONFIG_PCI_P2PDMA */
+static inline enum pci_p2pdma_map_type
+pci_p2pdma_map_segment(struct pci_p2pdma_map_state *state, struct device *dev,
+                      struct scatterlist *sg)
+{
+       return PCI_P2PDMA_MAP_NOT_SUPPORTED;
+}
+#endif /* CONFIG_PCI_P2PDMA */
+
 #endif /* _LINUX_DMA_MAP_OPS_H */