^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #ifndef _LINUX_IOMMU_COMMON_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #define _LINUX_IOMMU_COMMON_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <linux/spinlock_types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <asm/page.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #define IOMMU_POOL_HASHBITS 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #define IOMMU_NR_POOLS (1 << IOMMU_POOL_HASHBITS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #define IOMMU_ERROR_CODE (~(unsigned long) 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) struct iommu_pool {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) unsigned long start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) unsigned long end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) unsigned long hint;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) spinlock_t lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) struct iommu_map_table {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) unsigned long table_map_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) unsigned long table_shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) unsigned long nr_pools;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) void (*lazy_flush)(struct iommu_map_table *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) unsigned long poolsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) struct iommu_pool pools[IOMMU_NR_POOLS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) u32 flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define IOMMU_HAS_LARGE_POOL 0x00000001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define IOMMU_NO_SPAN_BOUND 0x00000002
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define IOMMU_NEED_FLUSH 0x00000004
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct iommu_pool large_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) unsigned long *map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) extern void iommu_tbl_pool_init(struct iommu_map_table *iommu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) unsigned long num_entries,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) u32 table_shift,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) void (*lazy_flush)(struct iommu_map_table *),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) bool large_pool, u32 npools,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) bool skip_span_boundary_check);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) extern unsigned long iommu_tbl_range_alloc(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) struct iommu_map_table *iommu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) unsigned long npages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) unsigned long *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) unsigned long mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) unsigned int align_order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) extern void iommu_tbl_range_free(struct iommu_map_table *iommu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) u64 dma_addr, unsigned long npages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) unsigned long entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #endif