staging: ion: add ion map iommu APIs
[firefly-linux-kernel-4.4.55.git] / drivers / staging / android / ion / ion_priv.h
index 0239883bffb72a82c0ffb05bc9aaaf0ee52f32aa..df1cc860c3a0f1beffd4f174cb73b537749f4736 100644 (file)
 
 struct ion_buffer *ion_handle_buffer(struct ion_handle *handle);
 
+#ifdef CONFIG_RK_IOMMU
+/**
+ * struct ion_iommu_map - represents a mapping of an ion buffer to an iommu
+ * @iova_addr - iommu virtual address
+ * @node - rb node to exist in the buffer's tree of iommu mappings
+ * @key - contains the iommu device info
+ * @ref - for reference counting this mapping
+ * @mapped_size - size of the iova space mapped
+ *             (may not be the same as the buffer size)
+ *
+ * Represents a mapping of one ion buffer to a particular iommu domain
+ * and address range. There may exist other mappings of this buffer in
+ * different domains or address ranges. All mappings will have the same
+ * cacheability and security.
+ */
+struct ion_iommu_map {
+       unsigned long iova_addr;
+       struct rb_node node;
+       unsigned long key;
+       struct ion_buffer *buffer;
+       struct kref ref;
+       int mapped_size;
+};
+#endif
+
 /**
  * struct ion_buffer - metadata for a particular buffer
  * @ref:               reference count
@@ -84,6 +109,10 @@ struct ion_buffer {
        int handle_count;
        char task_comm[TASK_COMM_LEN];
        pid_t pid;
+#ifdef CONFIG_RK_IOMMU
+       unsigned int iommu_map_cnt;
+       struct rb_root iommu_maps;
+#endif
 };
 void ion_buffer_destroy(struct ion_buffer *buffer);
 
@@ -121,6 +150,15 @@ struct ion_heap_ops {
        int (*map_user)(struct ion_heap *mapper, struct ion_buffer *buffer,
                        struct vm_area_struct *vma);
        int (*shrink)(struct ion_heap *heap, gfp_t gfp_mask, int nr_to_scan);
+#ifdef CONFIG_RK_IOMMU
+       int (*map_iommu)(struct ion_buffer *buffer,
+                        struct device *iommu_dev,
+                        struct ion_iommu_map *map_data,
+                        unsigned long iova_length,
+                        unsigned long flags);
+       void (*unmap_iommu)(struct device *iommu_dev,
+                           struct ion_iommu_map *data);
+#endif
 };
 
 /**