iova.h 1.6 KB

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