diff options
author | Jiang Liu <jiang.liu@linux.intel.com> | 2014-07-11 02:19:35 -0400 |
---|---|---|
committer | Joerg Roedel <jroedel@suse.de> | 2014-07-23 10:04:47 -0400 |
commit | 162d1b10d4d38065efec690c2b05ee90dfcf170c (patch) | |
tree | c1852cabd78648e446da9089f86754dda3cabe04 /drivers/iommu/intel-iommu.c | |
parent | d41a4adb1b9208a0ee59e6b4752853c1dd27cc2c (diff) |
iommu/vt-d: Introduce helper domain_pfn_within_range() to simplify code
Introduce helper function domain_pfn_within_range() to simplify code
and improve readability.
Signed-off-by: Jiang Liu <jiang.liu@linux.intel.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
Diffstat (limited to 'drivers/iommu/intel-iommu.c')
-rw-r--r-- | drivers/iommu/intel-iommu.c | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c index 0852b7021e4a..c9e65edaa2ad 100644 --- a/drivers/iommu/intel-iommu.c +++ b/drivers/iommu/intel-iommu.c | |||
@@ -549,6 +549,14 @@ static inline int domain_type_is_vm_or_si(struct dmar_domain *domain) | |||
549 | DOMAIN_FLAG_STATIC_IDENTITY); | 549 | DOMAIN_FLAG_STATIC_IDENTITY); |
550 | } | 550 | } |
551 | 551 | ||
552 | static inline int domain_pfn_supported(struct dmar_domain *domain, | ||
553 | unsigned long pfn) | ||
554 | { | ||
555 | int addr_width = agaw_to_width(domain->agaw) - VTD_PAGE_SHIFT; | ||
556 | |||
557 | return !(addr_width < BITS_PER_LONG && pfn >> addr_width); | ||
558 | } | ||
559 | |||
552 | static int __iommu_calculate_agaw(struct intel_iommu *iommu, int max_gaw) | 560 | static int __iommu_calculate_agaw(struct intel_iommu *iommu, int max_gaw) |
553 | { | 561 | { |
554 | unsigned long sagaw; | 562 | unsigned long sagaw; |
@@ -822,14 +830,13 @@ out: | |||
822 | static struct dma_pte *pfn_to_dma_pte(struct dmar_domain *domain, | 830 | static struct dma_pte *pfn_to_dma_pte(struct dmar_domain *domain, |
823 | unsigned long pfn, int *target_level) | 831 | unsigned long pfn, int *target_level) |
824 | { | 832 | { |
825 | int addr_width = agaw_to_width(domain->agaw) - VTD_PAGE_SHIFT; | ||
826 | struct dma_pte *parent, *pte = NULL; | 833 | struct dma_pte *parent, *pte = NULL; |
827 | int level = agaw_to_level(domain->agaw); | 834 | int level = agaw_to_level(domain->agaw); |
828 | int offset; | 835 | int offset; |
829 | 836 | ||
830 | BUG_ON(!domain->pgd); | 837 | BUG_ON(!domain->pgd); |
831 | 838 | ||
832 | if (addr_width < BITS_PER_LONG && pfn >> addr_width) | 839 | if (!domain_pfn_supported(domain, pfn)) |
833 | /* Address beyond IOMMU's addressing capabilities. */ | 840 | /* Address beyond IOMMU's addressing capabilities. */ |
834 | return NULL; | 841 | return NULL; |
835 | 842 | ||
@@ -912,12 +919,11 @@ static void dma_pte_clear_range(struct dmar_domain *domain, | |||
912 | unsigned long start_pfn, | 919 | unsigned long start_pfn, |
913 | unsigned long last_pfn) | 920 | unsigned long last_pfn) |
914 | { | 921 | { |
915 | int addr_width = agaw_to_width(domain->agaw) - VTD_PAGE_SHIFT; | ||
916 | unsigned int large_page = 1; | 922 | unsigned int large_page = 1; |
917 | struct dma_pte *first_pte, *pte; | 923 | struct dma_pte *first_pte, *pte; |
918 | 924 | ||
919 | BUG_ON(addr_width < BITS_PER_LONG && start_pfn >> addr_width); | 925 | BUG_ON(!domain_pfn_supported(domain, start_pfn)); |
920 | BUG_ON(addr_width < BITS_PER_LONG && last_pfn >> addr_width); | 926 | BUG_ON(!domain_pfn_supported(domain, last_pfn)); |
921 | BUG_ON(start_pfn > last_pfn); | 927 | BUG_ON(start_pfn > last_pfn); |
922 | 928 | ||
923 | /* we don't need lock here; nobody else touches the iova range */ | 929 | /* we don't need lock here; nobody else touches the iova range */ |
@@ -978,10 +984,8 @@ static void dma_pte_free_pagetable(struct dmar_domain *domain, | |||
978 | unsigned long start_pfn, | 984 | unsigned long start_pfn, |
979 | unsigned long last_pfn) | 985 | unsigned long last_pfn) |
980 | { | 986 | { |
981 | int addr_width = agaw_to_width(domain->agaw) - VTD_PAGE_SHIFT; | 987 | BUG_ON(!domain_pfn_supported(domain, start_pfn)); |
982 | 988 | BUG_ON(!domain_pfn_supported(domain, last_pfn)); | |
983 | BUG_ON(addr_width < BITS_PER_LONG && start_pfn >> addr_width); | ||
984 | BUG_ON(addr_width < BITS_PER_LONG && last_pfn >> addr_width); | ||
985 | BUG_ON(start_pfn > last_pfn); | 989 | BUG_ON(start_pfn > last_pfn); |
986 | 990 | ||
987 | dma_pte_clear_range(domain, start_pfn, last_pfn); | 991 | dma_pte_clear_range(domain, start_pfn, last_pfn); |
@@ -1083,11 +1087,10 @@ struct page *domain_unmap(struct dmar_domain *domain, | |||
1083 | unsigned long start_pfn, | 1087 | unsigned long start_pfn, |
1084 | unsigned long last_pfn) | 1088 | unsigned long last_pfn) |
1085 | { | 1089 | { |
1086 | int addr_width = agaw_to_width(domain->agaw) - VTD_PAGE_SHIFT; | ||
1087 | struct page *freelist = NULL; | 1090 | struct page *freelist = NULL; |
1088 | 1091 | ||
1089 | BUG_ON(addr_width < BITS_PER_LONG && start_pfn >> addr_width); | 1092 | BUG_ON(!domain_pfn_supported(domain, start_pfn)); |
1090 | BUG_ON(addr_width < BITS_PER_LONG && last_pfn >> addr_width); | 1093 | BUG_ON(!domain_pfn_supported(domain, last_pfn)); |
1091 | BUG_ON(start_pfn > last_pfn); | 1094 | BUG_ON(start_pfn > last_pfn); |
1092 | 1095 | ||
1093 | /* we don't need lock here; nobody else touches the iova range */ | 1096 | /* we don't need lock here; nobody else touches the iova range */ |
@@ -1974,12 +1977,11 @@ static int __domain_mapping(struct dmar_domain *domain, unsigned long iov_pfn, | |||
1974 | { | 1977 | { |
1975 | struct dma_pte *first_pte = NULL, *pte = NULL; | 1978 | struct dma_pte *first_pte = NULL, *pte = NULL; |
1976 | phys_addr_t uninitialized_var(pteval); | 1979 | phys_addr_t uninitialized_var(pteval); |
1977 | int addr_width = agaw_to_width(domain->agaw) - VTD_PAGE_SHIFT; | ||
1978 | unsigned long sg_res; | 1980 | unsigned long sg_res; |
1979 | unsigned int largepage_lvl = 0; | 1981 | unsigned int largepage_lvl = 0; |
1980 | unsigned long lvl_pages = 0; | 1982 | unsigned long lvl_pages = 0; |
1981 | 1983 | ||
1982 | BUG_ON(addr_width < BITS_PER_LONG && (iov_pfn + nr_pages - 1) >> addr_width); | 1984 | BUG_ON(!domain_pfn_supported(domain, iov_pfn + nr_pages - 1)); |
1983 | 1985 | ||
1984 | if ((prot & (DMA_PTE_READ|DMA_PTE_WRITE)) == 0) | 1986 | if ((prot & (DMA_PTE_READ|DMA_PTE_WRITE)) == 0) |
1985 | return -EINVAL; | 1987 | return -EINVAL; |