iommu-common.h 1.4 KB

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