18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef _LINUX_IOMMU_COMMON_H
38c2ecf20Sopenharmony_ci#define _LINUX_IOMMU_COMMON_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include <linux/spinlock_types.h>
68c2ecf20Sopenharmony_ci#include <linux/device.h>
78c2ecf20Sopenharmony_ci#include <asm/page.h>
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#define IOMMU_POOL_HASHBITS     4
108c2ecf20Sopenharmony_ci#define IOMMU_NR_POOLS          (1 << IOMMU_POOL_HASHBITS)
118c2ecf20Sopenharmony_ci#define IOMMU_ERROR_CODE	(~(unsigned long) 0)
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_cistruct iommu_pool {
148c2ecf20Sopenharmony_ci	unsigned long	start;
158c2ecf20Sopenharmony_ci	unsigned long	end;
168c2ecf20Sopenharmony_ci	unsigned long	hint;
178c2ecf20Sopenharmony_ci	spinlock_t	lock;
188c2ecf20Sopenharmony_ci};
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_cistruct iommu_map_table {
218c2ecf20Sopenharmony_ci	unsigned long		table_map_base;
228c2ecf20Sopenharmony_ci	unsigned long		table_shift;
238c2ecf20Sopenharmony_ci	unsigned long		nr_pools;
248c2ecf20Sopenharmony_ci	void			(*lazy_flush)(struct iommu_map_table *);
258c2ecf20Sopenharmony_ci	unsigned long		poolsize;
268c2ecf20Sopenharmony_ci	struct iommu_pool	pools[IOMMU_NR_POOLS];
278c2ecf20Sopenharmony_ci	u32			flags;
288c2ecf20Sopenharmony_ci#define	IOMMU_HAS_LARGE_POOL	0x00000001
298c2ecf20Sopenharmony_ci#define	IOMMU_NO_SPAN_BOUND	0x00000002
308c2ecf20Sopenharmony_ci#define	IOMMU_NEED_FLUSH	0x00000004
318c2ecf20Sopenharmony_ci	struct iommu_pool	large_pool;
328c2ecf20Sopenharmony_ci	unsigned long		*map;
338c2ecf20Sopenharmony_ci};
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ciextern void iommu_tbl_pool_init(struct iommu_map_table *iommu,
368c2ecf20Sopenharmony_ci				unsigned long num_entries,
378c2ecf20Sopenharmony_ci				u32 table_shift,
388c2ecf20Sopenharmony_ci				void (*lazy_flush)(struct iommu_map_table *),
398c2ecf20Sopenharmony_ci				bool large_pool, u32 npools,
408c2ecf20Sopenharmony_ci				bool skip_span_boundary_check);
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ciextern unsigned long iommu_tbl_range_alloc(struct device *dev,
438c2ecf20Sopenharmony_ci					   struct iommu_map_table *iommu,
448c2ecf20Sopenharmony_ci					   unsigned long npages,
458c2ecf20Sopenharmony_ci					   unsigned long *handle,
468c2ecf20Sopenharmony_ci					   unsigned long mask,
478c2ecf20Sopenharmony_ci					   unsigned int align_order);
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ciextern void iommu_tbl_range_free(struct iommu_map_table *iommu,
508c2ecf20Sopenharmony_ci				 u64 dma_addr, unsigned long npages,
518c2ecf20Sopenharmony_ci				 unsigned long entry);
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci#endif
54