1 #ifndef _IOMMU_H
2 #define _IOMMU_H
3 
4 struct udevice;
5 
6 struct iommu_ops {
7 	/**
8 	 * init() - Connect a device to it's IOMMU, called before probe()
9 	 * The iommu device can be fetched through dev->iommu
10 	 *
11 	 * @iommu_dev:	IOMMU device
12 	 * @dev:	Device to connect
13 	 * @return 0 if OK, -errno on error
14 	 */
15 	int (*connect)(struct udevice *dev);
16 	/**
17 	 * map() - map DMA memory
18 	 *
19 	 * @dev:	device for which to map DMA memory
20 	 * @addr:	CPU address of the memory
21 	 * @size:	size of the memory
22 	 * @return DMA address for the device
23 	 */
24 	dma_addr_t (*map)(struct udevice *dev, void *addr, size_t size);
25 
26 	/**
27 	 * unmap() - unmap DMA memory
28 	 *
29 	 * @dev:	device for which to unmap DMA memory
30 	 * @addr:	DMA address of the memory
31 	 * @size:	size of the memory
32 	 */
33 	void (*unmap)(struct udevice *dev, dma_addr_t addr, size_t size);
34 };
35 
36 #if (CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)) && \
37 	CONFIG_IS_ENABLED(IOMMU)
38 int dev_iommu_enable(struct udevice *dev);
39 #else
dev_iommu_enable(struct udevice * dev)40 static inline int dev_iommu_enable(struct udevice *dev)
41 {
42 	return 0;
43 }
44 #endif
45 
46 dma_addr_t dev_iommu_dma_map(struct udevice *dev, void *addr, size_t size);
47 void dev_iommu_dma_unmap(struct udevice *dev, dma_addr_t addr, size_t size);
48 
49 #endif
50