diff options
author | Robin Murphy <robin.murphy@arm.com> | 2015-01-12 12:51:16 -0500 |
---|---|---|
committer | Joerg Roedel <jroedel@suse.de> | 2015-01-19 08:55:22 -0500 |
commit | 0fb5fe874c42942e16c450ae05da453e13a1c09e (patch) | |
tree | 3103ddfe5741c14f46acb7048c81fe2e7b1d0621 /include/linux/iova.h | |
parent | 1b72250076dde4276acecf3a7da722b185703e78 (diff) |
iommu: Make IOVA domain page size explicit
Systems may contain heterogeneous IOMMUs supporting differing minimum
page sizes, which may also not be common with the CPU page size.
Thus it is practical to have an explicit notion of IOVA granularity
to simplify handling of mapping and allocation constraints.
As an initial step, move the IOVA page granularity from an implicit
compile-time constant to a per-domain property so we can make use
of it in IOVA domain context at runtime. To keep the abstraction tidy,
extend the little API of inline iova_* helpers to parallel some of the
equivalent PAGE_* macros.
Signed-off-by: Robin Murphy <robin.murphy@arm.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
Diffstat (limited to 'include/linux/iova.h')
-rw-r--r-- | include/linux/iova.h | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/include/linux/iova.h b/include/linux/iova.h index 591b19626b46..3920a19d8194 100644 --- a/include/linux/iova.h +++ b/include/linux/iova.h | |||
@@ -28,6 +28,7 @@ struct iova_domain { | |||
28 | spinlock_t iova_rbtree_lock; /* Lock to protect update of rbtree */ | 28 | spinlock_t iova_rbtree_lock; /* Lock to protect update of rbtree */ |
29 | struct rb_root rbroot; /* iova domain rbtree root */ | 29 | struct rb_root rbroot; /* iova domain rbtree root */ |
30 | struct rb_node *cached32_node; /* Save last alloced node */ | 30 | struct rb_node *cached32_node; /* Save last alloced node */ |
31 | unsigned long granule; /* pfn granularity for this domain */ | ||
31 | unsigned long start_pfn; /* Lower limit for this domain */ | 32 | unsigned long start_pfn; /* Lower limit for this domain */ |
32 | unsigned long dma_32bit_pfn; | 33 | unsigned long dma_32bit_pfn; |
33 | }; | 34 | }; |
@@ -37,6 +38,36 @@ static inline unsigned long iova_size(struct iova *iova) | |||
37 | return iova->pfn_hi - iova->pfn_lo + 1; | 38 | return iova->pfn_hi - iova->pfn_lo + 1; |
38 | } | 39 | } |
39 | 40 | ||
41 | static inline unsigned long iova_shift(struct iova_domain *iovad) | ||
42 | { | ||
43 | return __ffs(iovad->granule); | ||
44 | } | ||
45 | |||
46 | static inline unsigned long iova_mask(struct iova_domain *iovad) | ||
47 | { | ||
48 | return iovad->granule - 1; | ||
49 | } | ||
50 | |||
51 | static inline size_t iova_offset(struct iova_domain *iovad, dma_addr_t iova) | ||
52 | { | ||
53 | return iova & iova_mask(iovad); | ||
54 | } | ||
55 | |||
56 | static inline size_t iova_align(struct iova_domain *iovad, size_t size) | ||
57 | { | ||
58 | return ALIGN(size, iovad->granule); | ||
59 | } | ||
60 | |||
61 | static inline dma_addr_t iova_dma_addr(struct iova_domain *iovad, struct iova *iova) | ||
62 | { | ||
63 | return (dma_addr_t)iova->pfn_lo << iova_shift(iovad); | ||
64 | } | ||
65 | |||
66 | static inline unsigned long iova_pfn(struct iova_domain *iovad, dma_addr_t iova) | ||
67 | { | ||
68 | return iova >> iova_shift(iovad); | ||
69 | } | ||
70 | |||
40 | int iommu_iova_cache_init(void); | 71 | int iommu_iova_cache_init(void); |
41 | void iommu_iova_cache_destroy(void); | 72 | void iommu_iova_cache_destroy(void); |
42 | 73 | ||
@@ -50,8 +81,8 @@ struct iova *alloc_iova(struct iova_domain *iovad, unsigned long size, | |||
50 | struct iova *reserve_iova(struct iova_domain *iovad, unsigned long pfn_lo, | 81 | struct iova *reserve_iova(struct iova_domain *iovad, unsigned long pfn_lo, |
51 | unsigned long pfn_hi); | 82 | unsigned long pfn_hi); |
52 | void copy_reserved_iova(struct iova_domain *from, struct iova_domain *to); | 83 | void copy_reserved_iova(struct iova_domain *from, struct iova_domain *to); |
53 | void init_iova_domain(struct iova_domain *iovad, unsigned long start_pfn, | 84 | void init_iova_domain(struct iova_domain *iovad, unsigned long granule, |
54 | unsigned long pfn_32bit); | 85 | unsigned long start_pfn, unsigned long pfn_32bit); |
55 | struct iova *find_iova(struct iova_domain *iovad, unsigned long pfn); | 86 | struct iova *find_iova(struct iova_domain *iovad, unsigned long pfn); |
56 | void put_iova_domain(struct iova_domain *iovad); | 87 | void put_iova_domain(struct iova_domain *iovad); |
57 | struct iova *split_and_remove_iova(struct iova_domain *iovad, | 88 | struct iova *split_and_remove_iova(struct iova_domain *iovad, |