iova.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright (c) 2006, Intel Corporation.
  3. *
  4. * This file is released under the GPLv2.
  5. *
  6. * Copyright (C) 2006 Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
  7. *
  8. */
  9. #ifndef _IOVA_H_
  10. #define _IOVA_H_
  11. #include <linux/types.h>
  12. #include <linux/kernel.h>
  13. #include <linux/rbtree.h>
  14. #include <linux/dma-mapping.h>
  15. /* IO virtual address start page frame number */
  16. #define IOVA_START_PFN (1)
  17. /* iova structure */
  18. struct iova {
  19. struct rb_node node;
  20. unsigned long pfn_hi; /* IOMMU dish out addr hi */
  21. unsigned long pfn_lo; /* IOMMU dish out addr lo */
  22. };
  23. /* holds all the iova translations for a domain */
  24. struct iova_domain {
  25. spinlock_t iova_alloc_lock;/* Lock to protect iova allocation */
  26. spinlock_t iova_rbtree_lock; /* Lock to protect update of rbtree */
  27. struct rb_root rbroot; /* iova domain rbtree root */
  28. struct rb_node *cached32_node; /* Save last alloced node */
  29. unsigned long dma_32bit_pfn;
  30. };
  31. struct iova *alloc_iova_mem(void);
  32. void free_iova_mem(struct iova *iova);
  33. void free_iova(struct iova_domain *iovad, unsigned long pfn);
  34. void __free_iova(struct iova_domain *iovad, struct iova *iova);
  35. struct iova *alloc_iova(struct iova_domain *iovad, unsigned long size,
  36. unsigned long limit_pfn,
  37. bool size_aligned);
  38. struct iova *reserve_iova(struct iova_domain *iovad, unsigned long pfn_lo,
  39. unsigned long pfn_hi);
  40. void copy_reserved_iova(struct iova_domain *from, struct iova_domain *to);
  41. void init_iova_domain(struct iova_domain *iovad, unsigned long pfn_32bit);
  42. struct iova *find_iova(struct iova_domain *iovad, unsigned long pfn);
  43. void put_iova_domain(struct iova_domain *iovad);
  44. #endif