aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86')
-rw-r--r--arch/x86/kernel/amd_iommu.c89
1 files changed, 42 insertions, 47 deletions
diff --git a/arch/x86/kernel/amd_iommu.c b/arch/x86/kernel/amd_iommu.c
index 90b365024c24..14b60c0cdc70 100644
--- a/arch/x86/kernel/amd_iommu.c
+++ b/arch/x86/kernel/amd_iommu.c
@@ -57,11 +57,6 @@ struct iommu_cmd {
57 u32 data[4]; 57 u32 data[4];
58}; 58};
59 59
60static int dma_ops_unity_map(struct dma_ops_domain *dma_dom,
61 struct unity_map_entry *e);
62static void dma_ops_reserve_addresses(struct dma_ops_domain *dom,
63 unsigned long start_page,
64 unsigned int pages);
65static void reset_iommu_command_buffer(struct amd_iommu *iommu); 60static void reset_iommu_command_buffer(struct amd_iommu *iommu);
66static void update_domain(struct protection_domain *domain); 61static void update_domain(struct protection_domain *domain);
67 62
@@ -823,28 +818,6 @@ static int iommu_for_unity_map(struct amd_iommu *iommu,
823} 818}
824 819
825/* 820/*
826 * Init the unity mappings for a specific IOMMU in the system
827 *
828 * Basically iterates over all unity mapping entries and applies them to
829 * the default domain DMA of that IOMMU if necessary.
830 */
831static int iommu_init_unity_mappings(struct amd_iommu *iommu)
832{
833 struct unity_map_entry *entry;
834 int ret;
835
836 list_for_each_entry(entry, &amd_iommu_unity_map, list) {
837 if (!iommu_for_unity_map(iommu, entry))
838 continue;
839 ret = dma_ops_unity_map(iommu->default_dom, entry);
840 if (ret)
841 return ret;
842 }
843
844 return 0;
845}
846
847/*
848 * This function actually applies the mapping to the page table of the 821 * This function actually applies the mapping to the page table of the
849 * dma_ops domain. 822 * dma_ops domain.
850 */ 823 */
@@ -873,6 +846,28 @@ static int dma_ops_unity_map(struct dma_ops_domain *dma_dom,
873} 846}
874 847
875/* 848/*
849 * Init the unity mappings for a specific IOMMU in the system
850 *
851 * Basically iterates over all unity mapping entries and applies them to
852 * the default domain DMA of that IOMMU if necessary.
853 */
854static int iommu_init_unity_mappings(struct amd_iommu *iommu)
855{
856 struct unity_map_entry *entry;
857 int ret;
858
859 list_for_each_entry(entry, &amd_iommu_unity_map, list) {
860 if (!iommu_for_unity_map(iommu, entry))
861 continue;
862 ret = dma_ops_unity_map(iommu->default_dom, entry);
863 if (ret)
864 return ret;
865 }
866
867 return 0;
868}
869
870/*
876 * Inits the unity mappings required for a specific device 871 * Inits the unity mappings required for a specific device
877 */ 872 */
878static int init_unity_mappings_for_device(struct dma_ops_domain *dma_dom, 873static int init_unity_mappings_for_device(struct dma_ops_domain *dma_dom,
@@ -909,6 +904,26 @@ static int init_unity_mappings_for_device(struct dma_ops_domain *dma_dom,
909 */ 904 */
910 905
911/* 906/*
907 * Used to reserve address ranges in the aperture (e.g. for exclusion
908 * ranges.
909 */
910static void dma_ops_reserve_addresses(struct dma_ops_domain *dom,
911 unsigned long start_page,
912 unsigned int pages)
913{
914 unsigned int i, last_page = dom->aperture_size >> PAGE_SHIFT;
915
916 if (start_page + pages > last_page)
917 pages = last_page - start_page;
918
919 for (i = start_page; i < start_page + pages; ++i) {
920 int index = i / APERTURE_RANGE_PAGES;
921 int page = i % APERTURE_RANGE_PAGES;
922 __set_bit(page, dom->aperture[index]->bitmap);
923 }
924}
925
926/*
912 * This function is used to add a new aperture range to an existing 927 * This function is used to add a new aperture range to an existing
913 * aperture in case of dma_ops domain allocation or address allocation 928 * aperture in case of dma_ops domain allocation or address allocation
914 * failure. 929 * failure.
@@ -1166,26 +1181,6 @@ static void domain_id_free(int id)
1166 write_unlock_irqrestore(&amd_iommu_devtable_lock, flags); 1181 write_unlock_irqrestore(&amd_iommu_devtable_lock, flags);
1167} 1182}
1168 1183
1169/*
1170 * Used to reserve address ranges in the aperture (e.g. for exclusion
1171 * ranges.
1172 */
1173static void dma_ops_reserve_addresses(struct dma_ops_domain *dom,
1174 unsigned long start_page,
1175 unsigned int pages)
1176{
1177 unsigned int i, last_page = dom->aperture_size >> PAGE_SHIFT;
1178
1179 if (start_page + pages > last_page)
1180 pages = last_page - start_page;
1181
1182 for (i = start_page; i < start_page + pages; ++i) {
1183 int index = i / APERTURE_RANGE_PAGES;
1184 int page = i % APERTURE_RANGE_PAGES;
1185 __set_bit(page, dom->aperture[index]->bitmap);
1186 }
1187}
1188
1189static void free_pagetable(struct protection_domain *domain) 1184static void free_pagetable(struct protection_domain *domain)
1190{ 1185{
1191 int i, j; 1186 int i, j;