Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branches 'arm/exynos', 'arm/mediatek', 'arm/msm', 'arm/smmu', 'virtio', 'x86/vt-d', 'x86/amd' and 'core' into next

+2530 -1493
+25 -9
Documentation/admin-guide/kernel-parameters.txt
··· 2266 2266 2267 2267 ivrs_ioapic [HW,X86-64] 2268 2268 Provide an override to the IOAPIC-ID<->DEVICE-ID 2269 - mapping provided in the IVRS ACPI table. For 2270 - example, to map IOAPIC-ID decimal 10 to 2271 - PCI device 00:14.0 write the parameter as: 2269 + mapping provided in the IVRS ACPI table. 2270 + By default, PCI segment is 0, and can be omitted. 2271 + For example: 2272 + * To map IOAPIC-ID decimal 10 to PCI device 00:14.0 2273 + write the parameter as: 2272 2274 ivrs_ioapic[10]=00:14.0 2275 + * To map IOAPIC-ID decimal 10 to PCI segment 0x1 and 2276 + PCI device 00:14.0 write the parameter as: 2277 + ivrs_ioapic[10]=0001:00:14.0 2273 2278 2274 2279 ivrs_hpet [HW,X86-64] 2275 2280 Provide an override to the HPET-ID<->DEVICE-ID 2276 - mapping provided in the IVRS ACPI table. For 2277 - example, to map HPET-ID decimal 0 to 2278 - PCI device 00:14.0 write the parameter as: 2281 + mapping provided in the IVRS ACPI table. 2282 + By default, PCI segment is 0, and can be omitted. 2283 + For example: 2284 + * To map HPET-ID decimal 0 to PCI device 00:14.0 2285 + write the parameter as: 2279 2286 ivrs_hpet[0]=00:14.0 2287 + * To map HPET-ID decimal 10 to PCI segment 0x1 and 2288 + PCI device 00:14.0 write the parameter as: 2289 + ivrs_ioapic[10]=0001:00:14.0 2280 2290 2281 2291 ivrs_acpihid [HW,X86-64] 2282 2292 Provide an override to the ACPI-HID:UID<->DEVICE-ID 2283 - mapping provided in the IVRS ACPI table. For 2284 - example, to map UART-HID:UID AMD0020:0 to 2285 - PCI device 00:14.5 write the parameter as: 2293 + mapping provided in the IVRS ACPI table. 2294 + 2295 + For example, to map UART-HID:UID AMD0020:0 to 2296 + PCI segment 0x1 and PCI device ID 00:14.5, 2297 + write the parameter as: 2298 + ivrs_acpihid[0001:00:14.5]=AMD0020:0 2299 + 2300 + By default, PCI segment is 0, and can be omitted. 2301 + For example, PCI device 00:14.5 write the parameter as: 2286 2302 ivrs_acpihid[00:14.5]=AMD0020:0 2287 2303 2288 2304 js= [HW,JOY] Analog joystick
+1
Documentation/devicetree/bindings/iommu/arm,smmu.yaml
··· 42 42 - qcom,sdx55-smmu-500 43 43 - qcom,sdx65-smmu-500 44 44 - qcom,sm6350-smmu-500 45 + - qcom,sm6375-smmu-500 45 46 - qcom,sm8150-smmu-500 46 47 - qcom,sm8250-smmu-500 47 48 - qcom,sm8350-smmu-500
+17
Documentation/devicetree/bindings/iommu/mediatek,iommu.yaml
··· 101 101 items: 102 102 - const: bclk 103 103 104 + mediatek,infracfg: 105 + $ref: /schemas/types.yaml#/definitions/phandle 106 + description: The phandle to the mediatek infracfg syscon 107 + 104 108 mediatek,larbs: 105 109 $ref: /schemas/types.yaml#/definitions/phandle-array 106 110 minItems: 1 ··· 171 167 required: 172 168 - power-domains 173 169 170 + - if: 171 + properties: 172 + compatible: 173 + contains: 174 + enum: 175 + - mediatek,mt2712-m4u 176 + - mediatek,mt8173-m4u 177 + 178 + then: 179 + required: 180 + - mediatek,infracfg 181 + 174 182 - if: # The IOMMUs don't have larbs. 175 183 not: 176 184 properties: ··· 207 191 interrupts = <GIC_SPI 139 IRQ_TYPE_LEVEL_LOW>; 208 192 clocks = <&infracfg CLK_INFRA_M4U>; 209 193 clock-names = "bclk"; 194 + mediatek,infracfg = <&infracfg>; 210 195 mediatek,larbs = <&larb0>, <&larb1>, <&larb2>, 211 196 <&larb3>, <&larb4>, <&larb5>; 212 197 #iommu-cells = <1>;
+12 -2
MAINTAINERS
··· 10076 10076 S: Supported 10077 10077 T: git git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu.git 10078 10078 F: drivers/iommu/intel/ 10079 - F: include/linux/intel-iommu.h 10080 10079 F: include/linux/intel-svm.h 10081 10080 10082 10081 INTEL IOP-ADMA DMA DRIVER ··· 10447 10448 F: fs/iomap/ 10448 10449 F: include/linux/iomap.h 10449 10450 10450 - IOMMU DRIVERS 10451 + IOMMU DMA-API LAYER 10452 + M: Robin Murphy <robin.murphy@arm.com> 10453 + L: iommu@lists.linux.dev 10454 + S: Maintained 10455 + T: git git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu.git 10456 + F: drivers/iommu/dma-iommu.c 10457 + F: drivers/iommu/iova.c 10458 + F: include/linux/dma-iommu.h 10459 + F: include/linux/iova.h 10460 + 10461 + IOMMU SUBSYSTEM 10451 10462 M: Joerg Roedel <joro@8bytes.org> 10452 10463 M: Will Deacon <will@kernel.org> 10464 + R: Robin Murphy <robin.murphy@arm.com> 10453 10465 L: iommu@lists.linux.dev 10454 10466 S: Maintained 10455 10467 T: git git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu.git
-15
arch/x86/kernel/tboot.c
··· 6 6 * Copyright (c) 2006-2009, Intel Corporation 7 7 */ 8 8 9 - #include <linux/intel-iommu.h> 10 9 #include <linux/init_task.h> 11 10 #include <linux/spinlock.h> 12 11 #include <linux/export.h> ··· 514 515 /* don't unmap heap because dmar.c needs access to this */ 515 516 516 517 return dmar_tbl; 517 - } 518 - 519 - int tboot_force_iommu(void) 520 - { 521 - if (!tboot_enabled()) 522 - return 0; 523 - 524 - if (no_iommu || dmar_disabled) 525 - pr_warn("Forcing Intel-IOMMU to enabled\n"); 526 - 527 - dmar_disabled = 0; 528 - no_iommu = 0; 529 - 530 - return 1; 531 518 }
-1
arch/x86/kvm/x86.c
··· 41 41 #include <linux/mman.h> 42 42 #include <linux/highmem.h> 43 43 #include <linux/iommu.h> 44 - #include <linux/intel-iommu.h> 45 44 #include <linux/cpufreq.h> 46 45 #include <linux/user-return-notifier.h> 47 46 #include <linux/srcu.h>
+341 -21
drivers/acpi/arm64/iort.c
··· 788 788 } 789 789 790 790 #ifdef CONFIG_IOMMU_API 791 + static void iort_rmr_free(struct device *dev, 792 + struct iommu_resv_region *region) 793 + { 794 + struct iommu_iort_rmr_data *rmr_data; 795 + 796 + rmr_data = container_of(region, struct iommu_iort_rmr_data, rr); 797 + kfree(rmr_data->sids); 798 + kfree(rmr_data); 799 + } 800 + 801 + static struct iommu_iort_rmr_data *iort_rmr_alloc( 802 + struct acpi_iort_rmr_desc *rmr_desc, 803 + int prot, enum iommu_resv_type type, 804 + u32 *sids, u32 num_sids) 805 + { 806 + struct iommu_iort_rmr_data *rmr_data; 807 + struct iommu_resv_region *region; 808 + u32 *sids_copy; 809 + u64 addr = rmr_desc->base_address, size = rmr_desc->length; 810 + 811 + rmr_data = kmalloc(sizeof(*rmr_data), GFP_KERNEL); 812 + if (!rmr_data) 813 + return NULL; 814 + 815 + /* Create a copy of SIDs array to associate with this rmr_data */ 816 + sids_copy = kmemdup(sids, num_sids * sizeof(*sids), GFP_KERNEL); 817 + if (!sids_copy) { 818 + kfree(rmr_data); 819 + return NULL; 820 + } 821 + rmr_data->sids = sids_copy; 822 + rmr_data->num_sids = num_sids; 823 + 824 + if (!IS_ALIGNED(addr, SZ_64K) || !IS_ALIGNED(size, SZ_64K)) { 825 + /* PAGE align base addr and size */ 826 + addr &= PAGE_MASK; 827 + size = PAGE_ALIGN(size + offset_in_page(rmr_desc->base_address)); 828 + 829 + pr_err(FW_BUG "RMR descriptor[0x%llx - 0x%llx] not aligned to 64K, continue with [0x%llx - 0x%llx]\n", 830 + rmr_desc->base_address, 831 + rmr_desc->base_address + rmr_desc->length - 1, 832 + addr, addr + size - 1); 833 + } 834 + 835 + region = &rmr_data->rr; 836 + INIT_LIST_HEAD(&region->list); 837 + region->start = addr; 838 + region->length = size; 839 + region->prot = prot; 840 + region->type = type; 841 + region->free = iort_rmr_free; 842 + 843 + return rmr_data; 844 + } 845 + 846 + static void iort_rmr_desc_check_overlap(struct acpi_iort_rmr_desc *desc, 847 + u32 count) 848 + { 849 + int i, j; 850 + 851 + for (i = 0; i < count; i++) { 852 + u64 end, start = desc[i].base_address, length = desc[i].length; 853 + 854 + if (!length) { 855 + pr_err(FW_BUG "RMR descriptor[0x%llx] with zero length, continue anyway\n", 856 + start); 857 + continue; 858 + } 859 + 860 + end = start + length - 1; 861 + 862 + /* Check for address overlap */ 863 + for (j = i + 1; j < count; j++) { 864 + u64 e_start = desc[j].base_address; 865 + u64 e_end = e_start + desc[j].length - 1; 866 + 867 + if (start <= e_end && end >= e_start) 868 + pr_err(FW_BUG "RMR descriptor[0x%llx - 0x%llx] overlaps, continue anyway\n", 869 + start, end); 870 + } 871 + } 872 + } 873 + 874 + /* 875 + * Please note, we will keep the already allocated RMR reserve 876 + * regions in case of a memory allocation failure. 877 + */ 878 + static void iort_get_rmrs(struct acpi_iort_node *node, 879 + struct acpi_iort_node *smmu, 880 + u32 *sids, u32 num_sids, 881 + struct list_head *head) 882 + { 883 + struct acpi_iort_rmr *rmr = (struct acpi_iort_rmr *)node->node_data; 884 + struct acpi_iort_rmr_desc *rmr_desc; 885 + int i; 886 + 887 + rmr_desc = ACPI_ADD_PTR(struct acpi_iort_rmr_desc, node, 888 + rmr->rmr_offset); 889 + 890 + iort_rmr_desc_check_overlap(rmr_desc, rmr->rmr_count); 891 + 892 + for (i = 0; i < rmr->rmr_count; i++, rmr_desc++) { 893 + struct iommu_iort_rmr_data *rmr_data; 894 + enum iommu_resv_type type; 895 + int prot = IOMMU_READ | IOMMU_WRITE; 896 + 897 + if (rmr->flags & ACPI_IORT_RMR_REMAP_PERMITTED) 898 + type = IOMMU_RESV_DIRECT_RELAXABLE; 899 + else 900 + type = IOMMU_RESV_DIRECT; 901 + 902 + if (rmr->flags & ACPI_IORT_RMR_ACCESS_PRIVILEGE) 903 + prot |= IOMMU_PRIV; 904 + 905 + /* Attributes 0x00 - 0x03 represents device memory */ 906 + if (ACPI_IORT_RMR_ACCESS_ATTRIBUTES(rmr->flags) <= 907 + ACPI_IORT_RMR_ATTR_DEVICE_GRE) 908 + prot |= IOMMU_MMIO; 909 + else if (ACPI_IORT_RMR_ACCESS_ATTRIBUTES(rmr->flags) == 910 + ACPI_IORT_RMR_ATTR_NORMAL_IWB_OWB) 911 + prot |= IOMMU_CACHE; 912 + 913 + rmr_data = iort_rmr_alloc(rmr_desc, prot, type, 914 + sids, num_sids); 915 + if (!rmr_data) 916 + return; 917 + 918 + list_add_tail(&rmr_data->rr.list, head); 919 + } 920 + } 921 + 922 + static u32 *iort_rmr_alloc_sids(u32 *sids, u32 count, u32 id_start, 923 + u32 new_count) 924 + { 925 + u32 *new_sids; 926 + u32 total_count = count + new_count; 927 + int i; 928 + 929 + new_sids = krealloc_array(sids, count + new_count, 930 + sizeof(*new_sids), GFP_KERNEL); 931 + if (!new_sids) 932 + return NULL; 933 + 934 + for (i = count; i < total_count; i++) 935 + new_sids[i] = id_start++; 936 + 937 + return new_sids; 938 + } 939 + 940 + static bool iort_rmr_has_dev(struct device *dev, u32 id_start, 941 + u32 id_count) 942 + { 943 + int i; 944 + struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); 945 + 946 + /* 947 + * Make sure the kernel has preserved the boot firmware PCIe 948 + * configuration. This is required to ensure that the RMR PCIe 949 + * StreamIDs are still valid (Refer: ARM DEN 0049E.d Section 3.1.1.5). 950 + */ 951 + if (dev_is_pci(dev)) { 952 + struct pci_dev *pdev = to_pci_dev(dev); 953 + struct pci_host_bridge *host = pci_find_host_bridge(pdev->bus); 954 + 955 + if (!host->preserve_config) 956 + return false; 957 + } 958 + 959 + for (i = 0; i < fwspec->num_ids; i++) { 960 + if (fwspec->ids[i] >= id_start && 961 + fwspec->ids[i] <= id_start + id_count) 962 + return true; 963 + } 964 + 965 + return false; 966 + } 967 + 968 + static void iort_node_get_rmr_info(struct acpi_iort_node *node, 969 + struct acpi_iort_node *iommu, 970 + struct device *dev, struct list_head *head) 971 + { 972 + struct acpi_iort_node *smmu = NULL; 973 + struct acpi_iort_rmr *rmr; 974 + struct acpi_iort_id_mapping *map; 975 + u32 *sids = NULL; 976 + u32 num_sids = 0; 977 + int i; 978 + 979 + if (!node->mapping_offset || !node->mapping_count) { 980 + pr_err(FW_BUG "Invalid ID mapping, skipping RMR node %p\n", 981 + node); 982 + return; 983 + } 984 + 985 + rmr = (struct acpi_iort_rmr *)node->node_data; 986 + if (!rmr->rmr_offset || !rmr->rmr_count) 987 + return; 988 + 989 + map = ACPI_ADD_PTR(struct acpi_iort_id_mapping, node, 990 + node->mapping_offset); 991 + 992 + /* 993 + * Go through the ID mappings and see if we have a match for SMMU 994 + * and dev(if !NULL). If found, get the sids for the Node. 995 + * Please note, id_count is equal to the number of IDs in the 996 + * range minus one. 997 + */ 998 + for (i = 0; i < node->mapping_count; i++, map++) { 999 + struct acpi_iort_node *parent; 1000 + 1001 + if (!map->id_count) 1002 + continue; 1003 + 1004 + parent = ACPI_ADD_PTR(struct acpi_iort_node, iort_table, 1005 + map->output_reference); 1006 + if (parent != iommu) 1007 + continue; 1008 + 1009 + /* If dev is valid, check RMR node corresponds to the dev SID */ 1010 + if (dev && !iort_rmr_has_dev(dev, map->output_base, 1011 + map->id_count)) 1012 + continue; 1013 + 1014 + /* Retrieve SIDs associated with the Node. */ 1015 + sids = iort_rmr_alloc_sids(sids, num_sids, map->output_base, 1016 + map->id_count + 1); 1017 + if (!sids) 1018 + return; 1019 + 1020 + num_sids += map->id_count + 1; 1021 + } 1022 + 1023 + if (!sids) 1024 + return; 1025 + 1026 + iort_get_rmrs(node, smmu, sids, num_sids, head); 1027 + kfree(sids); 1028 + } 1029 + 1030 + static void iort_find_rmrs(struct acpi_iort_node *iommu, struct device *dev, 1031 + struct list_head *head) 1032 + { 1033 + struct acpi_table_iort *iort; 1034 + struct acpi_iort_node *iort_node, *iort_end; 1035 + int i; 1036 + 1037 + /* Only supports ARM DEN 0049E.d onwards */ 1038 + if (iort_table->revision < 5) 1039 + return; 1040 + 1041 + iort = (struct acpi_table_iort *)iort_table; 1042 + 1043 + iort_node = ACPI_ADD_PTR(struct acpi_iort_node, iort, 1044 + iort->node_offset); 1045 + iort_end = ACPI_ADD_PTR(struct acpi_iort_node, iort, 1046 + iort_table->length); 1047 + 1048 + for (i = 0; i < iort->node_count; i++) { 1049 + if (WARN_TAINT(iort_node >= iort_end, TAINT_FIRMWARE_WORKAROUND, 1050 + "IORT node pointer overflows, bad table!\n")) 1051 + return; 1052 + 1053 + if (iort_node->type == ACPI_IORT_NODE_RMR) 1054 + iort_node_get_rmr_info(iort_node, iommu, dev, head); 1055 + 1056 + iort_node = ACPI_ADD_PTR(struct acpi_iort_node, iort_node, 1057 + iort_node->length); 1058 + } 1059 + } 1060 + 1061 + /* 1062 + * Populate the RMR list associated with a given IOMMU and dev(if provided). 1063 + * If dev is NULL, the function populates all the RMRs associated with the 1064 + * given IOMMU. 1065 + */ 1066 + static void iort_iommu_rmr_get_resv_regions(struct fwnode_handle *iommu_fwnode, 1067 + struct device *dev, 1068 + struct list_head *head) 1069 + { 1070 + struct acpi_iort_node *iommu; 1071 + 1072 + iommu = iort_get_iort_node(iommu_fwnode); 1073 + if (!iommu) 1074 + return; 1075 + 1076 + iort_find_rmrs(iommu, dev, head); 1077 + } 1078 + 791 1079 static struct acpi_iort_node *iort_get_msi_resv_iommu(struct device *dev) 792 1080 { 793 1081 struct acpi_iort_node *iommu; ··· 1094 806 return NULL; 1095 807 } 1096 808 1097 - /** 1098 - * iort_iommu_msi_get_resv_regions - Reserved region driver helper 1099 - * @dev: Device from iommu_get_resv_regions() 1100 - * @head: Reserved region list from iommu_get_resv_regions() 1101 - * 1102 - * Returns: Number of msi reserved regions on success (0 if platform 1103 - * doesn't require the reservation or no associated msi regions), 1104 - * appropriate error value otherwise. The ITS interrupt translation 1105 - * spaces (ITS_base + SZ_64K, SZ_64K) associated with the device 1106 - * are the msi reserved regions. 809 + /* 810 + * Retrieve platform specific HW MSI reserve regions. 811 + * The ITS interrupt translation spaces (ITS_base + SZ_64K, SZ_64K) 812 + * associated with the device are the HW MSI reserved regions. 1107 813 */ 1108 - int iort_iommu_msi_get_resv_regions(struct device *dev, struct list_head *head) 814 + static void iort_iommu_msi_get_resv_regions(struct device *dev, 815 + struct list_head *head) 1109 816 { 1110 817 struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); 1111 818 struct acpi_iort_its_group *its; 1112 819 struct acpi_iort_node *iommu_node, *its_node = NULL; 1113 - int i, resv = 0; 820 + int i; 1114 821 1115 822 iommu_node = iort_get_msi_resv_iommu(dev); 1116 823 if (!iommu_node) 1117 - return 0; 824 + return; 1118 825 1119 826 /* 1120 827 * Current logic to reserve ITS regions relies on HW topologies ··· 1129 846 } 1130 847 1131 848 if (!its_node) 1132 - return 0; 849 + return; 1133 850 1134 851 /* Move to ITS specific data */ 1135 852 its = (struct acpi_iort_its_group *)its_node->node_data; ··· 1143 860 1144 861 region = iommu_alloc_resv_region(base + SZ_64K, SZ_64K, 1145 862 prot, IOMMU_RESV_MSI); 1146 - if (region) { 863 + if (region) 1147 864 list_add_tail(&region->list, head); 1148 - resv++; 1149 - } 1150 865 } 1151 866 } 1152 - 1153 - return (resv == its->its_count) ? resv : -ENODEV; 1154 867 } 868 + 869 + /** 870 + * iort_iommu_get_resv_regions - Generic helper to retrieve reserved regions. 871 + * @dev: Device from iommu_get_resv_regions() 872 + * @head: Reserved region list from iommu_get_resv_regions() 873 + */ 874 + void iort_iommu_get_resv_regions(struct device *dev, struct list_head *head) 875 + { 876 + struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); 877 + 878 + iort_iommu_msi_get_resv_regions(dev, head); 879 + iort_iommu_rmr_get_resv_regions(fwspec->iommu_fwnode, dev, head); 880 + } 881 + 882 + /** 883 + * iort_get_rmr_sids - Retrieve IORT RMR node reserved regions with 884 + * associated StreamIDs information. 885 + * @iommu_fwnode: fwnode associated with IOMMU 886 + * @head: Resereved region list 887 + */ 888 + void iort_get_rmr_sids(struct fwnode_handle *iommu_fwnode, 889 + struct list_head *head) 890 + { 891 + iort_iommu_rmr_get_resv_regions(iommu_fwnode, NULL, head); 892 + } 893 + EXPORT_SYMBOL_GPL(iort_get_rmr_sids); 894 + 895 + /** 896 + * iort_put_rmr_sids - Free memory allocated for RMR reserved regions. 897 + * @iommu_fwnode: fwnode associated with IOMMU 898 + * @head: Resereved region list 899 + */ 900 + void iort_put_rmr_sids(struct fwnode_handle *iommu_fwnode, 901 + struct list_head *head) 902 + { 903 + struct iommu_resv_region *entry, *next; 904 + 905 + list_for_each_entry_safe(entry, next, head, list) 906 + entry->free(NULL, entry); 907 + } 908 + EXPORT_SYMBOL_GPL(iort_put_rmr_sids); 1155 909 1156 910 static inline bool iort_iommu_driver_enabled(u8 type) 1157 911 { ··· 1354 1034 } 1355 1035 1356 1036 #else 1357 - int iort_iommu_msi_get_resv_regions(struct device *dev, struct list_head *head) 1358 - { return 0; } 1037 + void iort_iommu_get_resv_regions(struct device *dev, struct list_head *head) 1038 + { } 1359 1039 int iort_iommu_configure_id(struct device *dev, const u32 *input_id) 1360 1040 { return -ENODEV; } 1361 1041 #endif
+7 -10
drivers/char/agp/intel-gtt.c
··· 20 20 #include <linux/kernel.h> 21 21 #include <linux/pagemap.h> 22 22 #include <linux/agp_backend.h> 23 - #include <linux/intel-iommu.h> 23 + #include <linux/iommu.h> 24 24 #include <linux/delay.h> 25 25 #include <asm/smp.h> 26 26 #include "agp.h" ··· 573 573 */ 574 574 static inline int needs_ilk_vtd_wa(void) 575 575 { 576 - #ifdef CONFIG_INTEL_IOMMU 577 576 const unsigned short gpu_devid = intel_private.pcidev->device; 578 577 579 - /* Query intel_iommu to see if we need the workaround. Presumably that 580 - * was loaded first. 578 + /* 579 + * Query iommu subsystem to see if we need the workaround. Presumably 580 + * that was loaded first. 581 581 */ 582 - if ((gpu_devid == PCI_DEVICE_ID_INTEL_IRONLAKE_D_IG || 583 - gpu_devid == PCI_DEVICE_ID_INTEL_IRONLAKE_M_IG) && 584 - intel_iommu_gfx_mapped) 585 - return 1; 586 - #endif 587 - return 0; 582 + return ((gpu_devid == PCI_DEVICE_ID_INTEL_IRONLAKE_D_IG || 583 + gpu_devid == PCI_DEVICE_ID_INTEL_IRONLAKE_M_IG) && 584 + device_iommu_mapped(&intel_private.pcidev->dev)); 588 585 } 589 586 590 587 static bool intel_gtt_can_wc(void)
-1
drivers/gpu/drm/i915/display/intel_display.c
··· 27 27 #include <acpi/video.h> 28 28 #include <linux/i2c.h> 29 29 #include <linux/input.h> 30 - #include <linux/intel-iommu.h> 31 30 #include <linux/kernel.h> 32 31 #include <linux/module.h> 33 32 #include <linux/dma-resv.h>
-1
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c
··· 6 6 7 7 #include <linux/dma-resv.h> 8 8 #include <linux/highmem.h> 9 - #include <linux/intel-iommu.h> 10 9 #include <linux/sync_file.h> 11 10 #include <linux/uaccess.h> 12 11
+36
drivers/iommu/Kconfig
··· 144 144 select IRQ_MSI_IOMMU 145 145 select NEED_SG_DMA_LENGTH 146 146 147 + config IOMMU_DMA_PCI_SAC 148 + bool "Enable 64-bit legacy PCI optimisation by default" 149 + depends on IOMMU_DMA 150 + help 151 + Enable by default an IOMMU optimisation for 64-bit legacy PCI devices, 152 + wherein the DMA API layer will always first try to allocate a 32-bit 153 + DMA address suitable for a single address cycle, before falling back 154 + to allocating from the device's full usable address range. If your 155 + system has 64-bit legacy PCI devices in 32-bit slots where using dual 156 + address cycles reduces DMA throughput significantly, this may be 157 + beneficial to overall performance. 158 + 159 + If you have a modern PCI Express based system, this feature mostly just 160 + represents extra overhead in the allocation path for no practical 161 + benefit, and it should usually be preferable to say "n" here. 162 + 163 + However, beware that this feature has also historically papered over 164 + bugs where the IOMMU address width and/or device DMA mask is not set 165 + correctly. If device DMA problems and IOMMU faults start occurring 166 + after disabling this option, it is almost certainly indicative of a 167 + latent driver or firmware/BIOS bug, which would previously have only 168 + manifested with several gigabytes worth of concurrent DMA mappings. 169 + 170 + If this option is not set, the feature can still be re-enabled at 171 + boot time with the "iommu.forcedac=0" command-line argument. 172 + 147 173 # Shared Virtual Addressing 148 174 config IOMMU_SVA 149 175 bool ··· 388 362 help 389 363 When running on a Qualcomm platform that has the custom variant 390 364 of the ARM SMMU, this needs to be built into the SMMU driver. 365 + 366 + config ARM_SMMU_QCOM_DEBUG 367 + bool "ARM SMMU QCOM implementation defined debug support" 368 + depends on ARM_SMMU_QCOM 369 + help 370 + Support for implementation specific debug features in ARM SMMU 371 + hardware found in QTI platforms. 372 + 373 + Say Y here to enable debug for issues such as TLB sync timeouts 374 + which requires implementation defined register dumps. 391 375 392 376 config ARM_SMMU_V3 393 377 tristate "ARM Ltd. System MMU Version 3 (SMMUv3) Support"
+16 -2
drivers/iommu/amd/amd_iommu.h
··· 13 13 14 14 extern irqreturn_t amd_iommu_int_thread(int irq, void *data); 15 15 extern irqreturn_t amd_iommu_int_handler(int irq, void *data); 16 - extern void amd_iommu_apply_erratum_63(u16 devid); 16 + extern void amd_iommu_apply_erratum_63(struct amd_iommu *iommu, u16 devid); 17 17 extern void amd_iommu_restart_event_logging(struct amd_iommu *iommu); 18 18 extern int amd_iommu_init_devices(void); 19 19 extern void amd_iommu_uninit_devices(void); 20 20 extern void amd_iommu_init_notifier(void); 21 21 extern int amd_iommu_init_api(void); 22 + extern void amd_iommu_set_rlookup_table(struct amd_iommu *iommu, u16 devid); 22 23 23 24 #ifdef CONFIG_AMD_IOMMU_DEBUGFS 24 25 void amd_iommu_debugfs_setup(struct amd_iommu *iommu); ··· 115 114 amd_iommu_domain_set_pt_root(domain, 0); 116 115 } 117 116 117 + static inline int get_pci_sbdf_id(struct pci_dev *pdev) 118 + { 119 + int seg = pci_domain_nr(pdev->bus); 120 + u16 devid = pci_dev_id(pdev); 121 + 122 + return PCI_SEG_DEVID_TO_SBDF(seg, devid); 123 + } 118 124 119 125 extern bool translation_pre_enabled(struct amd_iommu *iommu); 120 126 extern bool amd_iommu_is_attach_deferred(struct device *dev); 121 - extern int __init add_special_device(u8 type, u8 id, u16 *devid, 127 + extern int __init add_special_device(u8 type, u8 id, u32 *devid, 122 128 bool cmd_line); 123 129 124 130 #ifdef CONFIG_DMI ··· 136 128 137 129 extern void amd_iommu_domain_set_pgtable(struct protection_domain *domain, 138 130 u64 *root, int mode); 131 + extern struct dev_table_entry *get_dev_table(struct amd_iommu *iommu); 132 + 133 + extern u64 amd_iommu_efr; 134 + extern u64 amd_iommu_efr2; 135 + 136 + extern bool amd_iommu_snp_en; 139 137 #endif
+128 -58
drivers/iommu/amd/amd_iommu_types.h
··· 67 67 #define MMIO_INTCAPXT_EVT_OFFSET 0x0170 68 68 #define MMIO_INTCAPXT_PPR_OFFSET 0x0178 69 69 #define MMIO_INTCAPXT_GALOG_OFFSET 0x0180 70 + #define MMIO_EXT_FEATURES2 0x01A0 70 71 #define MMIO_CMD_HEAD_OFFSET 0x2000 71 72 #define MMIO_CMD_TAIL_OFFSET 0x2008 72 73 #define MMIO_EVT_HEAD_OFFSET 0x2010 ··· 102 101 103 102 #define FEATURE_GLXVAL_SHIFT 14 104 103 #define FEATURE_GLXVAL_MASK (0x03ULL << FEATURE_GLXVAL_SHIFT) 104 + 105 + /* Extended Feature 2 Bits */ 106 + #define FEATURE_SNPAVICSUP_SHIFT 5 107 + #define FEATURE_SNPAVICSUP_MASK (0x07ULL << FEATURE_SNPAVICSUP_SHIFT) 108 + #define FEATURE_SNPAVICSUP_GAM(x) \ 109 + ((x & FEATURE_SNPAVICSUP_MASK) >> FEATURE_SNPAVICSUP_SHIFT == 0x1) 105 110 106 111 /* Note: 107 112 * The current driver only support 16-bit PASID. ··· 150 143 #define EVENT_FLAG_I 0x008 151 144 152 145 /* feature control bits */ 153 - #define CONTROL_IOMMU_EN 0x00ULL 154 - #define CONTROL_HT_TUN_EN 0x01ULL 155 - #define CONTROL_EVT_LOG_EN 0x02ULL 156 - #define CONTROL_EVT_INT_EN 0x03ULL 157 - #define CONTROL_COMWAIT_EN 0x04ULL 158 - #define CONTROL_INV_TIMEOUT 0x05ULL 159 - #define CONTROL_PASSPW_EN 0x08ULL 160 - #define CONTROL_RESPASSPW_EN 0x09ULL 161 - #define CONTROL_COHERENT_EN 0x0aULL 162 - #define CONTROL_ISOC_EN 0x0bULL 163 - #define CONTROL_CMDBUF_EN 0x0cULL 164 - #define CONTROL_PPRLOG_EN 0x0dULL 165 - #define CONTROL_PPRINT_EN 0x0eULL 166 - #define CONTROL_PPR_EN 0x0fULL 167 - #define CONTROL_GT_EN 0x10ULL 168 - #define CONTROL_GA_EN 0x11ULL 169 - #define CONTROL_GAM_EN 0x19ULL 170 - #define CONTROL_GALOG_EN 0x1CULL 171 - #define CONTROL_GAINT_EN 0x1DULL 172 - #define CONTROL_XT_EN 0x32ULL 173 - #define CONTROL_INTCAPXT_EN 0x33ULL 146 + #define CONTROL_IOMMU_EN 0 147 + #define CONTROL_HT_TUN_EN 1 148 + #define CONTROL_EVT_LOG_EN 2 149 + #define CONTROL_EVT_INT_EN 3 150 + #define CONTROL_COMWAIT_EN 4 151 + #define CONTROL_INV_TIMEOUT 5 152 + #define CONTROL_PASSPW_EN 8 153 + #define CONTROL_RESPASSPW_EN 9 154 + #define CONTROL_COHERENT_EN 10 155 + #define CONTROL_ISOC_EN 11 156 + #define CONTROL_CMDBUF_EN 12 157 + #define CONTROL_PPRLOG_EN 13 158 + #define CONTROL_PPRINT_EN 14 159 + #define CONTROL_PPR_EN 15 160 + #define CONTROL_GT_EN 16 161 + #define CONTROL_GA_EN 17 162 + #define CONTROL_GAM_EN 25 163 + #define CONTROL_GALOG_EN 28 164 + #define CONTROL_GAINT_EN 29 165 + #define CONTROL_XT_EN 50 166 + #define CONTROL_INTCAPXT_EN 51 167 + #define CONTROL_SNPAVIC_EN 61 174 168 175 169 #define CTRL_INV_TO_MASK (7 << CONTROL_INV_TIMEOUT) 176 170 #define CTRL_INV_TO_NONE 0 ··· 453 445 u32 *table; 454 446 }; 455 447 456 - extern struct irq_remap_table **irq_lookup_table; 457 - 458 448 /* Interrupt remapping feature used? */ 459 449 extern bool amd_iommu_irq_remap; 460 450 ··· 462 456 /* kmem_cache to get tables with 128 byte alignement */ 463 457 extern struct kmem_cache *amd_iommu_irq_cache; 464 458 459 + #define PCI_SBDF_TO_SEGID(sbdf) (((sbdf) >> 16) & 0xffff) 460 + #define PCI_SBDF_TO_DEVID(sbdf) ((sbdf) & 0xffff) 461 + #define PCI_SEG_DEVID_TO_SBDF(seg, devid) ((((u32)(seg) & 0xffff) << 16) | \ 462 + ((devid) & 0xffff)) 463 + 464 + /* Make iterating over all pci segment easier */ 465 + #define for_each_pci_segment(pci_seg) \ 466 + list_for_each_entry((pci_seg), &amd_iommu_pci_seg_list, list) 467 + #define for_each_pci_segment_safe(pci_seg, next) \ 468 + list_for_each_entry_safe((pci_seg), (next), &amd_iommu_pci_seg_list, list) 465 469 /* 466 470 * Make iterating over all IOMMUs easier 467 471 */ ··· 494 478 struct amd_iommu_fault { 495 479 u64 address; /* IO virtual address of the fault*/ 496 480 u32 pasid; /* Address space identifier */ 497 - u16 device_id; /* Originating PCI device id */ 481 + u32 sbdf; /* Originating PCI device id */ 498 482 u16 tag; /* PPR tag */ 499 483 u16 flags; /* Fault flags */ 500 484 501 485 }; 502 486 503 487 488 + struct amd_iommu; 504 489 struct iommu_domain; 505 490 struct irq_domain; 506 491 struct amd_irte_ops; ··· 548 531 }; 549 532 550 533 /* 534 + * This structure contains information about one PCI segment in the system. 535 + */ 536 + struct amd_iommu_pci_seg { 537 + /* List with all PCI segments in the system */ 538 + struct list_head list; 539 + 540 + /* List of all available dev_data structures */ 541 + struct llist_head dev_data_list; 542 + 543 + /* PCI segment number */ 544 + u16 id; 545 + 546 + /* Largest PCI device id we expect translation requests for */ 547 + u16 last_bdf; 548 + 549 + /* Size of the device table */ 550 + u32 dev_table_size; 551 + 552 + /* Size of the alias table */ 553 + u32 alias_table_size; 554 + 555 + /* Size of the rlookup table */ 556 + u32 rlookup_table_size; 557 + 558 + /* 559 + * device table virtual address 560 + * 561 + * Pointer to the per PCI segment device table. 562 + * It is indexed by the PCI device id or the HT unit id and contains 563 + * information about the domain the device belongs to as well as the 564 + * page table root pointer. 565 + */ 566 + struct dev_table_entry *dev_table; 567 + 568 + /* 569 + * The rlookup iommu table is used to find the IOMMU which is 570 + * responsible for a specific device. It is indexed by the PCI 571 + * device id. 572 + */ 573 + struct amd_iommu **rlookup_table; 574 + 575 + /* 576 + * This table is used to find the irq remapping table for a given 577 + * device id quickly. 578 + */ 579 + struct irq_remap_table **irq_lookup_table; 580 + 581 + /* 582 + * Pointer to a device table which the content of old device table 583 + * will be copied to. It's only be used in kdump kernel. 584 + */ 585 + struct dev_table_entry *old_dev_tbl_cpy; 586 + 587 + /* 588 + * The alias table is a driver specific data structure which contains the 589 + * mappings of the PCI device ids to the actual requestor ids on the IOMMU. 590 + * More than one device can share the same requestor id. 591 + */ 592 + u16 *alias_table; 593 + 594 + /* 595 + * A list of required unity mappings we find in ACPI. It is not locked 596 + * because as runtime it is only read. It is created at ACPI table 597 + * parsing time. 598 + */ 599 + struct list_head unity_map; 600 + }; 601 + 602 + /* 551 603 * Structure where we save information about one hardware AMD IOMMU in the 552 604 * system. 553 605 */ ··· 653 567 /* Extended features */ 654 568 u64 features; 655 569 570 + /* Extended features 2 */ 571 + u64 features2; 572 + 656 573 /* IOMMUv2 */ 657 574 bool is_iommu_v2; 658 575 ··· 670 581 u16 cap_ptr; 671 582 672 583 /* pci domain of this IOMMU */ 673 - u16 pci_seg; 584 + struct amd_iommu_pci_seg *pci_seg; 674 585 675 586 /* start of exclusion range of that IOMMU */ 676 587 u64 exclusion_start; ··· 755 666 struct list_head list; 756 667 u8 uid[ACPIHID_UID_LEN]; 757 668 u8 hid[ACPIHID_HID_LEN]; 758 - u16 devid; 759 - u16 root_devid; 669 + u32 devid; 670 + u32 root_devid; 760 671 bool cmd_line; 761 672 struct iommu_group *group; 762 673 }; ··· 764 675 struct devid_map { 765 676 struct list_head list; 766 677 u8 id; 767 - u16 devid; 678 + u32 devid; 768 679 bool cmd_line; 769 680 }; 770 681 ··· 778 689 struct list_head list; /* For domain->dev_list */ 779 690 struct llist_node dev_data_list; /* For global dev_data_list */ 780 691 struct protection_domain *domain; /* Domain the device is bound to */ 781 - struct pci_dev *pdev; 692 + struct device *dev; 782 693 u16 devid; /* PCI Device ID */ 783 694 bool iommu_v2; /* Device can make use of IOMMUv2 */ 784 695 struct { ··· 797 708 extern struct list_head ioapic_map; 798 709 extern struct list_head hpet_map; 799 710 extern struct list_head acpihid_map; 711 + 712 + /* 713 + * List with all PCI segments in the system. This list is not locked because 714 + * it is only written at driver initialization time 715 + */ 716 + extern struct list_head amd_iommu_pci_seg_list; 800 717 801 718 /* 802 719 * List with all IOMMUs in the system. This list is not locked because it is ··· 844 749 }; 845 750 846 751 /* 847 - * List of all unity mappings. It is not locked because as runtime it is only 848 - * read. It is created at ACPI table parsing time. 849 - */ 850 - extern struct list_head amd_iommu_unity_map; 851 - 852 - /* 853 752 * Data structures for device handling 854 753 */ 855 754 856 - /* 857 - * Device table used by hardware. Read and write accesses by software are 858 - * locked with the amd_iommu_pd_table lock. 859 - */ 860 - extern struct dev_table_entry *amd_iommu_dev_table; 861 - 862 - /* 863 - * Alias table to find requestor ids to device ids. Not locked because only 864 - * read on runtime. 865 - */ 866 - extern u16 *amd_iommu_alias_table; 867 - 868 - /* 869 - * Reverse lookup table to find the IOMMU which translates a specific device. 870 - */ 871 - extern struct amd_iommu **amd_iommu_rlookup_table; 872 - 873 755 /* size of the dma_ops aperture as power of 2 */ 874 756 extern unsigned amd_iommu_aperture_order; 875 - 876 - /* largest PCI device id we expect translation requests for */ 877 - extern u16 amd_iommu_last_bdf; 878 757 879 758 /* allocation bitmap for domain ids */ 880 759 extern unsigned long *amd_iommu_pd_alloc_bitmap; ··· 982 913 983 914 struct amd_ir_data { 984 915 u32 cached_ga_tag; 916 + struct amd_iommu *iommu; 985 917 struct irq_2_irte irq_2_irte; 986 918 struct msi_msg msi_entry; 987 919 void *entry; /* Pointer to union irte or struct irte_ga */ ··· 1000 930 1001 931 struct amd_irte_ops { 1002 932 void (*prepare)(void *, u32, bool, u8, u32, int); 1003 - void (*activate)(void *, u16, u16); 1004 - void (*deactivate)(void *, u16, u16); 1005 - void (*set_affinity)(void *, u16, u16, u8, u32); 933 + void (*activate)(struct amd_iommu *iommu, void *, u16, u16); 934 + void (*deactivate)(struct amd_iommu *iommu, void *, u16, u16); 935 + void (*set_affinity)(struct amd_iommu *iommu, void *, u16, u16, u8, u32); 1006 936 void *(*get)(struct irq_remap_table *, int); 1007 937 void (*set_allocated)(struct irq_remap_table *, int); 1008 938 bool (*is_allocated)(struct irq_remap_table *, int);
+608 -336
drivers/iommu/amd/init.c
··· 84 84 #define ACPI_DEVFLAG_ATSDIS 0x10000000 85 85 86 86 #define LOOP_TIMEOUT 2000000 87 + 88 + #define IVRS_GET_SBDF_ID(seg, bus, dev, fd) (((seg & 0xffff) << 16) | ((bus & 0xff) << 8) \ 89 + | ((dev & 0x1f) << 3) | (fn & 0x7)) 90 + 87 91 /* 88 92 * ACPI table definitions 89 93 * ··· 114 110 115 111 /* Following only valid on IVHD type 11h and 40h */ 116 112 u64 efr_reg; /* Exact copy of MMIO_EXT_FEATURES */ 117 - u64 res; 113 + u64 efr_reg2; 118 114 } __attribute__((packed)); 119 115 120 116 /* ··· 145 141 u16 length; 146 142 u16 devid; 147 143 u16 aux; 148 - u64 resv; 144 + u16 pci_seg; 145 + u8 resv[6]; 149 146 u64 range_start; 150 147 u64 range_length; 151 148 } __attribute__((packed)); ··· 164 159 static bool amd_iommu_force_enable __initdata; 165 160 static int amd_iommu_target_ivhd_type; 166 161 167 - u16 amd_iommu_last_bdf; /* largest PCI device id we have 168 - to handle */ 169 - LIST_HEAD(amd_iommu_unity_map); /* a list of required unity mappings 170 - we find in ACPI */ 162 + /* Global EFR and EFR2 registers */ 163 + u64 amd_iommu_efr; 164 + u64 amd_iommu_efr2; 171 165 166 + /* SNP is enabled on the system? */ 167 + bool amd_iommu_snp_en; 168 + EXPORT_SYMBOL(amd_iommu_snp_en); 169 + 170 + LIST_HEAD(amd_iommu_pci_seg_list); /* list of all PCI segments */ 172 171 LIST_HEAD(amd_iommu_list); /* list of all AMD IOMMUs in the 173 172 system */ 174 173 ··· 195 186 bool amd_iommu_force_isolation __read_mostly; 196 187 197 188 /* 198 - * Pointer to the device table which is shared by all AMD IOMMUs 199 - * it is indexed by the PCI device id or the HT unit id and contains 200 - * information about the domain the device belongs to as well as the 201 - * page table root pointer. 202 - */ 203 - struct dev_table_entry *amd_iommu_dev_table; 204 - /* 205 - * Pointer to a device table which the content of old device table 206 - * will be copied to. It's only be used in kdump kernel. 207 - */ 208 - static struct dev_table_entry *old_dev_tbl_cpy; 209 - 210 - /* 211 - * The alias table is a driver specific data structure which contains the 212 - * mappings of the PCI device ids to the actual requestor ids on the IOMMU. 213 - * More than one device can share the same requestor id. 214 - */ 215 - u16 *amd_iommu_alias_table; 216 - 217 - /* 218 - * The rlookup table is used to find the IOMMU which is responsible 219 - * for a specific device. It is also indexed by the PCI device id. 220 - */ 221 - struct amd_iommu **amd_iommu_rlookup_table; 222 - 223 - /* 224 - * This table is used to find the irq remapping table for a given device id 225 - * quickly. 226 - */ 227 - struct irq_remap_table **irq_lookup_table; 228 - 229 - /* 230 189 * AMD IOMMU allows up to 2^16 different protection domains. This is a bitmap 231 190 * to know which ones are already in use. 232 191 */ 233 192 unsigned long *amd_iommu_pd_alloc_bitmap; 234 - 235 - static u32 dev_table_size; /* size of the device table */ 236 - static u32 alias_table_size; /* size of the alias table */ 237 - static u32 rlookup_table_size; /* size if the rlookup table */ 238 193 239 194 enum iommu_init_state { 240 195 IOMMU_START_STATE, ··· 229 256 230 257 static int amd_iommu_enable_interrupts(void); 231 258 static int __init iommu_go_to_state(enum iommu_init_state state); 232 - static void init_device_table_dma(void); 259 + static void init_device_table_dma(struct amd_iommu_pci_seg *pci_seg); 233 260 234 261 static bool amd_iommu_pre_enabled = true; 235 262 ··· 254 281 iommu->flags |= AMD_IOMMU_FLAG_TRANS_PRE_ENABLED; 255 282 } 256 283 257 - static inline void update_last_devid(u16 devid) 258 - { 259 - if (devid > amd_iommu_last_bdf) 260 - amd_iommu_last_bdf = devid; 261 - } 262 - 263 - static inline unsigned long tbl_size(int entry_size) 284 + static inline unsigned long tbl_size(int entry_size, int last_bdf) 264 285 { 265 286 unsigned shift = PAGE_SHIFT + 266 - get_order(((int)amd_iommu_last_bdf + 1) * entry_size); 287 + get_order((last_bdf + 1) * entry_size); 267 288 268 289 return 1UL << shift; 269 290 } ··· 267 300 return amd_iommus_present; 268 301 } 269 302 270 - #ifdef CONFIG_IRQ_REMAP 271 - static bool check_feature_on_all_iommus(u64 mask) 303 + /* 304 + * Iterate through all the IOMMUs to get common EFR 305 + * masks among all IOMMUs and warn if found inconsistency. 306 + */ 307 + static void get_global_efr(void) 272 308 { 273 - bool ret = false; 274 309 struct amd_iommu *iommu; 275 310 276 311 for_each_iommu(iommu) { 277 - ret = iommu_feature(iommu, mask); 278 - if (!ret) 279 - return false; 312 + u64 tmp = iommu->features; 313 + u64 tmp2 = iommu->features2; 314 + 315 + if (list_is_first(&iommu->list, &amd_iommu_list)) { 316 + amd_iommu_efr = tmp; 317 + amd_iommu_efr2 = tmp2; 318 + continue; 319 + } 320 + 321 + if (amd_iommu_efr == tmp && 322 + amd_iommu_efr2 == tmp2) 323 + continue; 324 + 325 + pr_err(FW_BUG 326 + "Found inconsistent EFR/EFR2 %#llx,%#llx (global %#llx,%#llx) on iommu%d (%04x:%02x:%02x.%01x).\n", 327 + tmp, tmp2, amd_iommu_efr, amd_iommu_efr2, 328 + iommu->index, iommu->pci_seg->id, 329 + PCI_BUS_NUM(iommu->devid), PCI_SLOT(iommu->devid), 330 + PCI_FUNC(iommu->devid)); 331 + 332 + amd_iommu_efr &= tmp; 333 + amd_iommu_efr2 &= tmp2; 280 334 } 281 335 282 - return true; 336 + pr_info("Using global IVHD EFR:%#llx, EFR2:%#llx\n", amd_iommu_efr, amd_iommu_efr2); 283 337 } 284 - #endif 338 + 339 + static bool check_feature_on_all_iommus(u64 mask) 340 + { 341 + return !!(amd_iommu_efr & mask); 342 + } 285 343 286 344 /* 287 345 * For IVHD type 0x11/0x40, EFR is also available via IVHD. ··· 316 324 static void __init early_iommu_features_init(struct amd_iommu *iommu, 317 325 struct ivhd_header *h) 318 326 { 319 - if (amd_iommu_ivinfo & IOMMU_IVINFO_EFRSUP) 327 + if (amd_iommu_ivinfo & IOMMU_IVINFO_EFRSUP) { 320 328 iommu->features = h->efr_reg; 329 + iommu->features2 = h->efr_reg2; 330 + } 321 331 if (amd_iommu_ivinfo & IOMMU_IVINFO_DMA_REMAP) 322 332 amdr_ivrs_remap_support = true; 323 333 } ··· 393 399 u64 start = iommu_virt_to_phys((void *)iommu->cmd_sem); 394 400 u64 entry = start & PM_ADDR_MASK; 395 401 396 - if (!iommu_feature(iommu, FEATURE_SNP)) 402 + if (!check_feature_on_all_iommus(FEATURE_SNP)) 397 403 return; 398 404 399 405 /* Note: ··· 415 421 static void iommu_set_device_table(struct amd_iommu *iommu) 416 422 { 417 423 u64 entry; 424 + u32 dev_table_size = iommu->pci_seg->dev_table_size; 425 + void *dev_table = (void *)get_dev_table(iommu); 418 426 419 427 BUG_ON(iommu->mmio_base == NULL); 420 428 421 - entry = iommu_virt_to_phys(amd_iommu_dev_table); 429 + entry = iommu_virt_to_phys(dev_table); 422 430 entry |= (dev_table_size >> 12) - 1; 423 431 memcpy_toio(iommu->mmio_base + MMIO_DEV_TABLE_OFFSET, 424 432 &entry, sizeof(entry)); ··· 553 557 { 554 558 u8 *p = (void *)h, *end = (void *)h; 555 559 struct ivhd_entry *dev; 560 + int last_devid = -EINVAL; 556 561 557 562 u32 ivhd_size = get_ivhd_header_size(h); 558 563 ··· 570 573 switch (dev->type) { 571 574 case IVHD_DEV_ALL: 572 575 /* Use maximum BDF value for DEV_ALL */ 573 - update_last_devid(0xffff); 574 - break; 576 + return 0xffff; 575 577 case IVHD_DEV_SELECT: 576 578 case IVHD_DEV_RANGE_END: 577 579 case IVHD_DEV_ALIAS: 578 580 case IVHD_DEV_EXT_SELECT: 579 581 /* all the above subfield types refer to device ids */ 580 - update_last_devid(dev->devid); 582 + if (dev->devid > last_devid) 583 + last_devid = dev->devid; 581 584 break; 582 585 default: 583 586 break; ··· 587 590 588 591 WARN_ON(p != end); 589 592 590 - return 0; 593 + return last_devid; 591 594 } 592 595 593 596 static int __init check_ivrs_checksum(struct acpi_table_header *table) ··· 611 614 * id which we need to handle. This is the first of three functions which parse 612 615 * the ACPI table. So we check the checksum here. 613 616 */ 614 - static int __init find_last_devid_acpi(struct acpi_table_header *table) 617 + static int __init find_last_devid_acpi(struct acpi_table_header *table, u16 pci_seg) 615 618 { 616 619 u8 *p = (u8 *)table, *end = (u8 *)table; 617 620 struct ivhd_header *h; 621 + int last_devid, last_bdf = 0; 618 622 619 623 p += IVRS_HEADER_LENGTH; 620 624 621 625 end += table->length; 622 626 while (p < end) { 623 627 h = (struct ivhd_header *)p; 624 - if (h->type == amd_iommu_target_ivhd_type) { 625 - int ret = find_last_devid_from_ivhd(h); 628 + if (h->pci_seg == pci_seg && 629 + h->type == amd_iommu_target_ivhd_type) { 630 + last_devid = find_last_devid_from_ivhd(h); 626 631 627 - if (ret) 628 - return ret; 632 + if (last_devid < 0) 633 + return -EINVAL; 634 + if (last_devid > last_bdf) 635 + last_bdf = last_devid; 629 636 } 630 637 p += h->length; 631 638 } 632 639 WARN_ON(p != end); 633 640 634 - return 0; 641 + return last_bdf; 635 642 } 636 643 637 644 /**************************************************************************** 638 645 * 639 646 * The following functions belong to the code path which parses the ACPI table 640 647 * the second time. In this ACPI parsing iteration we allocate IOMMU specific 641 - * data structures, initialize the device/alias/rlookup table and also 642 - * basically initialize the hardware. 648 + * data structures, initialize the per PCI segment device/alias/rlookup table 649 + * and also basically initialize the hardware. 643 650 * 644 651 ****************************************************************************/ 652 + 653 + /* Allocate per PCI segment device table */ 654 + static inline int __init alloc_dev_table(struct amd_iommu_pci_seg *pci_seg) 655 + { 656 + pci_seg->dev_table = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO | GFP_DMA32, 657 + get_order(pci_seg->dev_table_size)); 658 + if (!pci_seg->dev_table) 659 + return -ENOMEM; 660 + 661 + return 0; 662 + } 663 + 664 + static inline void free_dev_table(struct amd_iommu_pci_seg *pci_seg) 665 + { 666 + free_pages((unsigned long)pci_seg->dev_table, 667 + get_order(pci_seg->dev_table_size)); 668 + pci_seg->dev_table = NULL; 669 + } 670 + 671 + /* Allocate per PCI segment IOMMU rlookup table. */ 672 + static inline int __init alloc_rlookup_table(struct amd_iommu_pci_seg *pci_seg) 673 + { 674 + pci_seg->rlookup_table = (void *)__get_free_pages( 675 + GFP_KERNEL | __GFP_ZERO, 676 + get_order(pci_seg->rlookup_table_size)); 677 + if (pci_seg->rlookup_table == NULL) 678 + return -ENOMEM; 679 + 680 + return 0; 681 + } 682 + 683 + static inline void free_rlookup_table(struct amd_iommu_pci_seg *pci_seg) 684 + { 685 + free_pages((unsigned long)pci_seg->rlookup_table, 686 + get_order(pci_seg->rlookup_table_size)); 687 + pci_seg->rlookup_table = NULL; 688 + } 689 + 690 + static inline int __init alloc_irq_lookup_table(struct amd_iommu_pci_seg *pci_seg) 691 + { 692 + pci_seg->irq_lookup_table = (void *)__get_free_pages( 693 + GFP_KERNEL | __GFP_ZERO, 694 + get_order(pci_seg->rlookup_table_size)); 695 + kmemleak_alloc(pci_seg->irq_lookup_table, 696 + pci_seg->rlookup_table_size, 1, GFP_KERNEL); 697 + if (pci_seg->irq_lookup_table == NULL) 698 + return -ENOMEM; 699 + 700 + return 0; 701 + } 702 + 703 + static inline void free_irq_lookup_table(struct amd_iommu_pci_seg *pci_seg) 704 + { 705 + kmemleak_free(pci_seg->irq_lookup_table); 706 + free_pages((unsigned long)pci_seg->irq_lookup_table, 707 + get_order(pci_seg->rlookup_table_size)); 708 + pci_seg->irq_lookup_table = NULL; 709 + } 710 + 711 + static int __init alloc_alias_table(struct amd_iommu_pci_seg *pci_seg) 712 + { 713 + int i; 714 + 715 + pci_seg->alias_table = (void *)__get_free_pages(GFP_KERNEL, 716 + get_order(pci_seg->alias_table_size)); 717 + if (!pci_seg->alias_table) 718 + return -ENOMEM; 719 + 720 + /* 721 + * let all alias entries point to itself 722 + */ 723 + for (i = 0; i <= pci_seg->last_bdf; ++i) 724 + pci_seg->alias_table[i] = i; 725 + 726 + return 0; 727 + } 728 + 729 + static void __init free_alias_table(struct amd_iommu_pci_seg *pci_seg) 730 + { 731 + free_pages((unsigned long)pci_seg->alias_table, 732 + get_order(pci_seg->alias_table_size)); 733 + pci_seg->alias_table = NULL; 734 + } 645 735 646 736 /* 647 737 * Allocates the command buffer. This buffer is per AMD IOMMU. We can ··· 808 724 void *buf = (void *)__get_free_pages(gfp, order); 809 725 810 726 if (buf && 811 - iommu_feature(iommu, FEATURE_SNP) && 727 + check_feature_on_all_iommus(FEATURE_SNP) && 812 728 set_memory_4k((unsigned long)buf, (1 << order))) { 813 729 free_pages((unsigned long)buf, order); 814 730 buf = NULL; ··· 899 815 #endif 900 816 } 901 817 818 + #ifdef CONFIG_IRQ_REMAP 902 819 static int iommu_ga_log_enable(struct amd_iommu *iommu) 903 820 { 904 - #ifdef CONFIG_IRQ_REMAP 905 821 u32 status, i; 906 822 u64 entry; 907 823 908 824 if (!iommu->ga_log) 909 825 return -EINVAL; 910 - 911 - /* Check if already running */ 912 - status = readl(iommu->mmio_base + MMIO_STATUS_OFFSET); 913 - if (WARN_ON(status & (MMIO_STATUS_GALOG_RUN_MASK))) 914 - return 0; 915 826 916 827 entry = iommu_virt_to_phys(iommu->ga_log) | GA_LOG_SIZE_512; 917 828 memcpy_toio(iommu->mmio_base + MMIO_GA_LOG_BASE_OFFSET, ··· 931 852 932 853 if (WARN_ON(i >= LOOP_TIMEOUT)) 933 854 return -EINVAL; 934 - #endif /* CONFIG_IRQ_REMAP */ 855 + 935 856 return 0; 936 857 } 937 858 938 859 static int iommu_init_ga_log(struct amd_iommu *iommu) 939 860 { 940 - #ifdef CONFIG_IRQ_REMAP 941 861 if (!AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir)) 942 862 return 0; 943 863 ··· 954 876 err_out: 955 877 free_ga_log(iommu); 956 878 return -EINVAL; 957 - #else 958 - return 0; 959 - #endif /* CONFIG_IRQ_REMAP */ 960 879 } 880 + #endif /* CONFIG_IRQ_REMAP */ 961 881 962 882 static int __init alloc_cwwb_sem(struct amd_iommu *iommu) 963 883 { ··· 992 916 } 993 917 994 918 /* sets a specific bit in the device table entry. */ 995 - static void set_dev_entry_bit(u16 devid, u8 bit) 919 + static void __set_dev_entry_bit(struct dev_table_entry *dev_table, 920 + u16 devid, u8 bit) 996 921 { 997 922 int i = (bit >> 6) & 0x03; 998 923 int _bit = bit & 0x3f; 999 924 1000 - amd_iommu_dev_table[devid].data[i] |= (1UL << _bit); 925 + dev_table[devid].data[i] |= (1UL << _bit); 1001 926 } 1002 927 1003 - static int get_dev_entry_bit(u16 devid, u8 bit) 928 + static void set_dev_entry_bit(struct amd_iommu *iommu, u16 devid, u8 bit) 929 + { 930 + struct dev_table_entry *dev_table = get_dev_table(iommu); 931 + 932 + return __set_dev_entry_bit(dev_table, devid, bit); 933 + } 934 + 935 + static int __get_dev_entry_bit(struct dev_table_entry *dev_table, 936 + u16 devid, u8 bit) 1004 937 { 1005 938 int i = (bit >> 6) & 0x03; 1006 939 int _bit = bit & 0x3f; 1007 940 1008 - return (amd_iommu_dev_table[devid].data[i] & (1UL << _bit)) >> _bit; 941 + return (dev_table[devid].data[i] & (1UL << _bit)) >> _bit; 1009 942 } 1010 943 1011 - 1012 - static bool copy_device_table(void) 944 + static int get_dev_entry_bit(struct amd_iommu *iommu, u16 devid, u8 bit) 1013 945 { 1014 - u64 int_ctl, int_tab_len, entry = 0, last_entry = 0; 946 + struct dev_table_entry *dev_table = get_dev_table(iommu); 947 + 948 + return __get_dev_entry_bit(dev_table, devid, bit); 949 + } 950 + 951 + static bool __copy_device_table(struct amd_iommu *iommu) 952 + { 953 + u64 int_ctl, int_tab_len, entry = 0; 954 + struct amd_iommu_pci_seg *pci_seg = iommu->pci_seg; 1015 955 struct dev_table_entry *old_devtb = NULL; 1016 956 u32 lo, hi, devid, old_devtb_size; 1017 957 phys_addr_t old_devtb_phys; 1018 - struct amd_iommu *iommu; 1019 958 u16 dom_id, dte_v, irq_v; 1020 959 gfp_t gfp_flag; 1021 960 u64 tmp; 1022 961 1023 - if (!amd_iommu_pre_enabled) 962 + /* Each IOMMU use separate device table with the same size */ 963 + lo = readl(iommu->mmio_base + MMIO_DEV_TABLE_OFFSET); 964 + hi = readl(iommu->mmio_base + MMIO_DEV_TABLE_OFFSET + 4); 965 + entry = (((u64) hi) << 32) + lo; 966 + 967 + old_devtb_size = ((entry & ~PAGE_MASK) + 1) << 12; 968 + if (old_devtb_size != pci_seg->dev_table_size) { 969 + pr_err("The device table size of IOMMU:%d is not expected!\n", 970 + iommu->index); 1024 971 return false; 1025 - 1026 - pr_warn("Translation is already enabled - trying to copy translation structures\n"); 1027 - for_each_iommu(iommu) { 1028 - /* All IOMMUs should use the same device table with the same size */ 1029 - lo = readl(iommu->mmio_base + MMIO_DEV_TABLE_OFFSET); 1030 - hi = readl(iommu->mmio_base + MMIO_DEV_TABLE_OFFSET + 4); 1031 - entry = (((u64) hi) << 32) + lo; 1032 - if (last_entry && last_entry != entry) { 1033 - pr_err("IOMMU:%d should use the same dev table as others!\n", 1034 - iommu->index); 1035 - return false; 1036 - } 1037 - last_entry = entry; 1038 - 1039 - old_devtb_size = ((entry & ~PAGE_MASK) + 1) << 12; 1040 - if (old_devtb_size != dev_table_size) { 1041 - pr_err("The device table size of IOMMU:%d is not expected!\n", 1042 - iommu->index); 1043 - return false; 1044 - } 1045 972 } 1046 973 1047 974 /* ··· 1060 981 } 1061 982 old_devtb = (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT) && is_kdump_kernel()) 1062 983 ? (__force void *)ioremap_encrypted(old_devtb_phys, 1063 - dev_table_size) 1064 - : memremap(old_devtb_phys, dev_table_size, MEMREMAP_WB); 984 + pci_seg->dev_table_size) 985 + : memremap(old_devtb_phys, pci_seg->dev_table_size, MEMREMAP_WB); 1065 986 1066 987 if (!old_devtb) 1067 988 return false; 1068 989 1069 990 gfp_flag = GFP_KERNEL | __GFP_ZERO | GFP_DMA32; 1070 - old_dev_tbl_cpy = (void *)__get_free_pages(gfp_flag, 1071 - get_order(dev_table_size)); 1072 - if (old_dev_tbl_cpy == NULL) { 991 + pci_seg->old_dev_tbl_cpy = (void *)__get_free_pages(gfp_flag, 992 + get_order(pci_seg->dev_table_size)); 993 + if (pci_seg->old_dev_tbl_cpy == NULL) { 1073 994 pr_err("Failed to allocate memory for copying old device table!\n"); 1074 995 memunmap(old_devtb); 1075 996 return false; 1076 997 } 1077 998 1078 - for (devid = 0; devid <= amd_iommu_last_bdf; ++devid) { 1079 - old_dev_tbl_cpy[devid] = old_devtb[devid]; 999 + for (devid = 0; devid <= pci_seg->last_bdf; ++devid) { 1000 + pci_seg->old_dev_tbl_cpy[devid] = old_devtb[devid]; 1080 1001 dom_id = old_devtb[devid].data[1] & DEV_DOMID_MASK; 1081 1002 dte_v = old_devtb[devid].data[0] & DTE_FLAG_V; 1082 1003 1083 1004 if (dte_v && dom_id) { 1084 - old_dev_tbl_cpy[devid].data[0] = old_devtb[devid].data[0]; 1085 - old_dev_tbl_cpy[devid].data[1] = old_devtb[devid].data[1]; 1005 + pci_seg->old_dev_tbl_cpy[devid].data[0] = old_devtb[devid].data[0]; 1006 + pci_seg->old_dev_tbl_cpy[devid].data[1] = old_devtb[devid].data[1]; 1086 1007 __set_bit(dom_id, amd_iommu_pd_alloc_bitmap); 1087 1008 /* If gcr3 table existed, mask it out */ 1088 1009 if (old_devtb[devid].data[0] & DTE_FLAG_GV) { 1089 1010 tmp = DTE_GCR3_VAL_B(~0ULL) << DTE_GCR3_SHIFT_B; 1090 1011 tmp |= DTE_GCR3_VAL_C(~0ULL) << DTE_GCR3_SHIFT_C; 1091 - old_dev_tbl_cpy[devid].data[1] &= ~tmp; 1012 + pci_seg->old_dev_tbl_cpy[devid].data[1] &= ~tmp; 1092 1013 tmp = DTE_GCR3_VAL_A(~0ULL) << DTE_GCR3_SHIFT_A; 1093 1014 tmp |= DTE_FLAG_GV; 1094 - old_dev_tbl_cpy[devid].data[0] &= ~tmp; 1015 + pci_seg->old_dev_tbl_cpy[devid].data[0] &= ~tmp; 1095 1016 } 1096 1017 } 1097 1018 ··· 1106 1027 return false; 1107 1028 } 1108 1029 1109 - old_dev_tbl_cpy[devid].data[2] = old_devtb[devid].data[2]; 1030 + pci_seg->old_dev_tbl_cpy[devid].data[2] = old_devtb[devid].data[2]; 1110 1031 } 1111 1032 } 1112 1033 memunmap(old_devtb); ··· 1114 1035 return true; 1115 1036 } 1116 1037 1117 - void amd_iommu_apply_erratum_63(u16 devid) 1038 + static bool copy_device_table(void) 1039 + { 1040 + struct amd_iommu *iommu; 1041 + struct amd_iommu_pci_seg *pci_seg; 1042 + 1043 + if (!amd_iommu_pre_enabled) 1044 + return false; 1045 + 1046 + pr_warn("Translation is already enabled - trying to copy translation structures\n"); 1047 + 1048 + /* 1049 + * All IOMMUs within PCI segment shares common device table. 1050 + * Hence copy device table only once per PCI segment. 1051 + */ 1052 + for_each_pci_segment(pci_seg) { 1053 + for_each_iommu(iommu) { 1054 + if (pci_seg->id != iommu->pci_seg->id) 1055 + continue; 1056 + if (!__copy_device_table(iommu)) 1057 + return false; 1058 + break; 1059 + } 1060 + } 1061 + 1062 + return true; 1063 + } 1064 + 1065 + void amd_iommu_apply_erratum_63(struct amd_iommu *iommu, u16 devid) 1118 1066 { 1119 1067 int sysmgt; 1120 1068 1121 - sysmgt = get_dev_entry_bit(devid, DEV_ENTRY_SYSMGT1) | 1122 - (get_dev_entry_bit(devid, DEV_ENTRY_SYSMGT2) << 1); 1069 + sysmgt = get_dev_entry_bit(iommu, devid, DEV_ENTRY_SYSMGT1) | 1070 + (get_dev_entry_bit(iommu, devid, DEV_ENTRY_SYSMGT2) << 1); 1123 1071 1124 1072 if (sysmgt == 0x01) 1125 - set_dev_entry_bit(devid, DEV_ENTRY_IW); 1126 - } 1127 - 1128 - /* Writes the specific IOMMU for a device into the rlookup table */ 1129 - static void __init set_iommu_for_device(struct amd_iommu *iommu, u16 devid) 1130 - { 1131 - amd_iommu_rlookup_table[devid] = iommu; 1073 + set_dev_entry_bit(iommu, devid, DEV_ENTRY_IW); 1132 1074 } 1133 1075 1134 1076 /* ··· 1160 1060 u16 devid, u32 flags, u32 ext_flags) 1161 1061 { 1162 1062 if (flags & ACPI_DEVFLAG_INITPASS) 1163 - set_dev_entry_bit(devid, DEV_ENTRY_INIT_PASS); 1063 + set_dev_entry_bit(iommu, devid, DEV_ENTRY_INIT_PASS); 1164 1064 if (flags & ACPI_DEVFLAG_EXTINT) 1165 - set_dev_entry_bit(devid, DEV_ENTRY_EINT_PASS); 1065 + set_dev_entry_bit(iommu, devid, DEV_ENTRY_EINT_PASS); 1166 1066 if (flags & ACPI_DEVFLAG_NMI) 1167 - set_dev_entry_bit(devid, DEV_ENTRY_NMI_PASS); 1067 + set_dev_entry_bit(iommu, devid, DEV_ENTRY_NMI_PASS); 1168 1068 if (flags & ACPI_DEVFLAG_SYSMGT1) 1169 - set_dev_entry_bit(devid, DEV_ENTRY_SYSMGT1); 1069 + set_dev_entry_bit(iommu, devid, DEV_ENTRY_SYSMGT1); 1170 1070 if (flags & ACPI_DEVFLAG_SYSMGT2) 1171 - set_dev_entry_bit(devid, DEV_ENTRY_SYSMGT2); 1071 + set_dev_entry_bit(iommu, devid, DEV_ENTRY_SYSMGT2); 1172 1072 if (flags & ACPI_DEVFLAG_LINT0) 1173 - set_dev_entry_bit(devid, DEV_ENTRY_LINT0_PASS); 1073 + set_dev_entry_bit(iommu, devid, DEV_ENTRY_LINT0_PASS); 1174 1074 if (flags & ACPI_DEVFLAG_LINT1) 1175 - set_dev_entry_bit(devid, DEV_ENTRY_LINT1_PASS); 1075 + set_dev_entry_bit(iommu, devid, DEV_ENTRY_LINT1_PASS); 1176 1076 1177 - amd_iommu_apply_erratum_63(devid); 1077 + amd_iommu_apply_erratum_63(iommu, devid); 1178 1078 1179 - set_iommu_for_device(iommu, devid); 1079 + amd_iommu_set_rlookup_table(iommu, devid); 1180 1080 } 1181 1081 1182 - int __init add_special_device(u8 type, u8 id, u16 *devid, bool cmd_line) 1082 + int __init add_special_device(u8 type, u8 id, u32 *devid, bool cmd_line) 1183 1083 { 1184 1084 struct devid_map *entry; 1185 1085 struct list_head *list; ··· 1216 1116 return 0; 1217 1117 } 1218 1118 1219 - static int __init add_acpi_hid_device(u8 *hid, u8 *uid, u16 *devid, 1119 + static int __init add_acpi_hid_device(u8 *hid, u8 *uid, u32 *devid, 1220 1120 bool cmd_line) 1221 1121 { 1222 1122 struct acpihid_map_entry *entry; ··· 1295 1195 { 1296 1196 u8 *p = (u8 *)h; 1297 1197 u8 *end = p, flags = 0; 1298 - u16 devid = 0, devid_start = 0, devid_to = 0; 1198 + u16 devid = 0, devid_start = 0, devid_to = 0, seg_id; 1299 1199 u32 dev_i, ext_flags = 0; 1300 1200 bool alias = false; 1301 1201 struct ivhd_entry *e; 1202 + struct amd_iommu_pci_seg *pci_seg = iommu->pci_seg; 1302 1203 u32 ivhd_size; 1303 1204 int ret; 1304 1205 ··· 1331 1230 1332 1231 while (p < end) { 1333 1232 e = (struct ivhd_entry *)p; 1233 + seg_id = pci_seg->id; 1234 + 1334 1235 switch (e->type) { 1335 1236 case IVHD_DEV_ALL: 1336 1237 1337 1238 DUMP_printk(" DEV_ALL\t\t\tflags: %02x\n", e->flags); 1338 1239 1339 - for (dev_i = 0; dev_i <= amd_iommu_last_bdf; ++dev_i) 1240 + for (dev_i = 0; dev_i <= pci_seg->last_bdf; ++dev_i) 1340 1241 set_dev_entry_from_acpi(iommu, dev_i, e->flags, 0); 1341 1242 break; 1342 1243 case IVHD_DEV_SELECT: 1343 1244 1344 - DUMP_printk(" DEV_SELECT\t\t\t devid: %02x:%02x.%x " 1245 + DUMP_printk(" DEV_SELECT\t\t\t devid: %04x:%02x:%02x.%x " 1345 1246 "flags: %02x\n", 1346 - PCI_BUS_NUM(e->devid), 1247 + seg_id, PCI_BUS_NUM(e->devid), 1347 1248 PCI_SLOT(e->devid), 1348 1249 PCI_FUNC(e->devid), 1349 1250 e->flags); ··· 1356 1253 case IVHD_DEV_SELECT_RANGE_START: 1357 1254 1358 1255 DUMP_printk(" DEV_SELECT_RANGE_START\t " 1359 - "devid: %02x:%02x.%x flags: %02x\n", 1360 - PCI_BUS_NUM(e->devid), 1256 + "devid: %04x:%02x:%02x.%x flags: %02x\n", 1257 + seg_id, PCI_BUS_NUM(e->devid), 1361 1258 PCI_SLOT(e->devid), 1362 1259 PCI_FUNC(e->devid), 1363 1260 e->flags); ··· 1369 1266 break; 1370 1267 case IVHD_DEV_ALIAS: 1371 1268 1372 - DUMP_printk(" DEV_ALIAS\t\t\t devid: %02x:%02x.%x " 1269 + DUMP_printk(" DEV_ALIAS\t\t\t devid: %04x:%02x:%02x.%x " 1373 1270 "flags: %02x devid_to: %02x:%02x.%x\n", 1374 - PCI_BUS_NUM(e->devid), 1271 + seg_id, PCI_BUS_NUM(e->devid), 1375 1272 PCI_SLOT(e->devid), 1376 1273 PCI_FUNC(e->devid), 1377 1274 e->flags, ··· 1383 1280 devid_to = e->ext >> 8; 1384 1281 set_dev_entry_from_acpi(iommu, devid , e->flags, 0); 1385 1282 set_dev_entry_from_acpi(iommu, devid_to, e->flags, 0); 1386 - amd_iommu_alias_table[devid] = devid_to; 1283 + pci_seg->alias_table[devid] = devid_to; 1387 1284 break; 1388 1285 case IVHD_DEV_ALIAS_RANGE: 1389 1286 1390 1287 DUMP_printk(" DEV_ALIAS_RANGE\t\t " 1391 - "devid: %02x:%02x.%x flags: %02x " 1392 - "devid_to: %02x:%02x.%x\n", 1393 - PCI_BUS_NUM(e->devid), 1288 + "devid: %04x:%02x:%02x.%x flags: %02x " 1289 + "devid_to: %04x:%02x:%02x.%x\n", 1290 + seg_id, PCI_BUS_NUM(e->devid), 1394 1291 PCI_SLOT(e->devid), 1395 1292 PCI_FUNC(e->devid), 1396 1293 e->flags, 1397 - PCI_BUS_NUM(e->ext >> 8), 1294 + seg_id, PCI_BUS_NUM(e->ext >> 8), 1398 1295 PCI_SLOT(e->ext >> 8), 1399 1296 PCI_FUNC(e->ext >> 8)); 1400 1297 ··· 1406 1303 break; 1407 1304 case IVHD_DEV_EXT_SELECT: 1408 1305 1409 - DUMP_printk(" DEV_EXT_SELECT\t\t devid: %02x:%02x.%x " 1306 + DUMP_printk(" DEV_EXT_SELECT\t\t devid: %04x:%02x:%02x.%x " 1410 1307 "flags: %02x ext: %08x\n", 1411 - PCI_BUS_NUM(e->devid), 1308 + seg_id, PCI_BUS_NUM(e->devid), 1412 1309 PCI_SLOT(e->devid), 1413 1310 PCI_FUNC(e->devid), 1414 1311 e->flags, e->ext); ··· 1420 1317 case IVHD_DEV_EXT_SELECT_RANGE: 1421 1318 1422 1319 DUMP_printk(" DEV_EXT_SELECT_RANGE\t devid: " 1423 - "%02x:%02x.%x flags: %02x ext: %08x\n", 1424 - PCI_BUS_NUM(e->devid), 1320 + "%04x:%02x:%02x.%x flags: %02x ext: %08x\n", 1321 + seg_id, PCI_BUS_NUM(e->devid), 1425 1322 PCI_SLOT(e->devid), 1426 1323 PCI_FUNC(e->devid), 1427 1324 e->flags, e->ext); ··· 1433 1330 break; 1434 1331 case IVHD_DEV_RANGE_END: 1435 1332 1436 - DUMP_printk(" DEV_RANGE_END\t\t devid: %02x:%02x.%x\n", 1437 - PCI_BUS_NUM(e->devid), 1333 + DUMP_printk(" DEV_RANGE_END\t\t devid: %04x:%02x:%02x.%x\n", 1334 + seg_id, PCI_BUS_NUM(e->devid), 1438 1335 PCI_SLOT(e->devid), 1439 1336 PCI_FUNC(e->devid)); 1440 1337 1441 1338 devid = e->devid; 1442 1339 for (dev_i = devid_start; dev_i <= devid; ++dev_i) { 1443 1340 if (alias) { 1444 - amd_iommu_alias_table[dev_i] = devid_to; 1341 + pci_seg->alias_table[dev_i] = devid_to; 1445 1342 set_dev_entry_from_acpi(iommu, 1446 1343 devid_to, flags, ext_flags); 1447 1344 } ··· 1452 1349 case IVHD_DEV_SPECIAL: { 1453 1350 u8 handle, type; 1454 1351 const char *var; 1455 - u16 devid; 1352 + u32 devid; 1456 1353 int ret; 1457 1354 1458 1355 handle = e->ext & 0xff; 1459 - devid = (e->ext >> 8) & 0xffff; 1356 + devid = PCI_SEG_DEVID_TO_SBDF(seg_id, (e->ext >> 8)); 1460 1357 type = (e->ext >> 24) & 0xff; 1461 1358 1462 1359 if (type == IVHD_SPECIAL_IOAPIC) ··· 1466 1363 else 1467 1364 var = "UNKNOWN"; 1468 1365 1469 - DUMP_printk(" DEV_SPECIAL(%s[%d])\t\tdevid: %02x:%02x.%x\n", 1366 + DUMP_printk(" DEV_SPECIAL(%s[%d])\t\tdevid: %04x:%02x:%02x.%x\n", 1470 1367 var, (int)handle, 1471 - PCI_BUS_NUM(devid), 1368 + seg_id, PCI_BUS_NUM(devid), 1472 1369 PCI_SLOT(devid), 1473 1370 PCI_FUNC(devid)); 1474 1371 ··· 1486 1383 break; 1487 1384 } 1488 1385 case IVHD_DEV_ACPI_HID: { 1489 - u16 devid; 1386 + u32 devid; 1490 1387 u8 hid[ACPIHID_HID_LEN]; 1491 1388 u8 uid[ACPIHID_UID_LEN]; 1492 1389 int ret; ··· 1529 1426 break; 1530 1427 } 1531 1428 1532 - devid = e->devid; 1533 - DUMP_printk(" DEV_ACPI_HID(%s[%s])\t\tdevid: %02x:%02x.%x\n", 1534 - hid, uid, 1429 + devid = PCI_SEG_DEVID_TO_SBDF(seg_id, e->devid); 1430 + DUMP_printk(" DEV_ACPI_HID(%s[%s])\t\tdevid: %04x:%02x:%02x.%x\n", 1431 + hid, uid, seg_id, 1535 1432 PCI_BUS_NUM(devid), 1536 1433 PCI_SLOT(devid), 1537 1434 PCI_FUNC(devid)); ··· 1559 1456 } 1560 1457 1561 1458 return 0; 1459 + } 1460 + 1461 + /* Allocate PCI segment data structure */ 1462 + static struct amd_iommu_pci_seg *__init alloc_pci_segment(u16 id, 1463 + struct acpi_table_header *ivrs_base) 1464 + { 1465 + struct amd_iommu_pci_seg *pci_seg; 1466 + int last_bdf; 1467 + 1468 + /* 1469 + * First parse ACPI tables to find the largest Bus/Dev/Func we need to 1470 + * handle in this PCI segment. Upon this information the shared data 1471 + * structures for the PCI segments in the system will be allocated. 1472 + */ 1473 + last_bdf = find_last_devid_acpi(ivrs_base, id); 1474 + if (last_bdf < 0) 1475 + return NULL; 1476 + 1477 + pci_seg = kzalloc(sizeof(struct amd_iommu_pci_seg), GFP_KERNEL); 1478 + if (pci_seg == NULL) 1479 + return NULL; 1480 + 1481 + pci_seg->last_bdf = last_bdf; 1482 + DUMP_printk("PCI segment : 0x%0x, last bdf : 0x%04x\n", id, last_bdf); 1483 + pci_seg->dev_table_size = tbl_size(DEV_TABLE_ENTRY_SIZE, last_bdf); 1484 + pci_seg->alias_table_size = tbl_size(ALIAS_TABLE_ENTRY_SIZE, last_bdf); 1485 + pci_seg->rlookup_table_size = tbl_size(RLOOKUP_TABLE_ENTRY_SIZE, last_bdf); 1486 + 1487 + pci_seg->id = id; 1488 + init_llist_head(&pci_seg->dev_data_list); 1489 + INIT_LIST_HEAD(&pci_seg->unity_map); 1490 + list_add_tail(&pci_seg->list, &amd_iommu_pci_seg_list); 1491 + 1492 + if (alloc_dev_table(pci_seg)) 1493 + return NULL; 1494 + if (alloc_alias_table(pci_seg)) 1495 + return NULL; 1496 + if (alloc_rlookup_table(pci_seg)) 1497 + return NULL; 1498 + 1499 + return pci_seg; 1500 + } 1501 + 1502 + static struct amd_iommu_pci_seg *__init get_pci_segment(u16 id, 1503 + struct acpi_table_header *ivrs_base) 1504 + { 1505 + struct amd_iommu_pci_seg *pci_seg; 1506 + 1507 + for_each_pci_segment(pci_seg) { 1508 + if (pci_seg->id == id) 1509 + return pci_seg; 1510 + } 1511 + 1512 + return alloc_pci_segment(id, ivrs_base); 1513 + } 1514 + 1515 + static void __init free_pci_segments(void) 1516 + { 1517 + struct amd_iommu_pci_seg *pci_seg, *next; 1518 + 1519 + for_each_pci_segment_safe(pci_seg, next) { 1520 + list_del(&pci_seg->list); 1521 + free_irq_lookup_table(pci_seg); 1522 + free_rlookup_table(pci_seg); 1523 + free_alias_table(pci_seg); 1524 + free_dev_table(pci_seg); 1525 + kfree(pci_seg); 1526 + } 1562 1527 } 1563 1528 1564 1529 static void __init free_iommu_one(struct amd_iommu *iommu) ··· 1713 1542 * together and also allocates the command buffer and programs the 1714 1543 * hardware. It does NOT enable the IOMMU. This is done afterwards. 1715 1544 */ 1716 - static int __init init_iommu_one(struct amd_iommu *iommu, struct ivhd_header *h) 1545 + static int __init init_iommu_one(struct amd_iommu *iommu, struct ivhd_header *h, 1546 + struct acpi_table_header *ivrs_base) 1717 1547 { 1718 - int ret; 1548 + struct amd_iommu_pci_seg *pci_seg; 1549 + 1550 + pci_seg = get_pci_segment(h->pci_seg, ivrs_base); 1551 + if (pci_seg == NULL) 1552 + return -ENOMEM; 1553 + iommu->pci_seg = pci_seg; 1719 1554 1720 1555 raw_spin_lock_init(&iommu->lock); 1721 1556 iommu->cmd_sem_val = 0; ··· 1743 1566 */ 1744 1567 iommu->devid = h->devid; 1745 1568 iommu->cap_ptr = h->cap_ptr; 1746 - iommu->pci_seg = h->pci_seg; 1747 1569 iommu->mmio_phys = h->mmio_phys; 1748 1570 1749 1571 switch (h->type) { ··· 1797 1621 if (!iommu->mmio_base) 1798 1622 return -ENOMEM; 1799 1623 1624 + return init_iommu_from_acpi(iommu, h); 1625 + } 1626 + 1627 + static int __init init_iommu_one_late(struct amd_iommu *iommu) 1628 + { 1629 + int ret; 1630 + 1800 1631 if (alloc_cwwb_sem(iommu)) 1801 1632 return -ENOMEM; 1802 1633 ··· 1825 1642 if (amd_iommu_pre_enabled) 1826 1643 amd_iommu_pre_enabled = translation_pre_enabled(iommu); 1827 1644 1828 - ret = init_iommu_from_acpi(iommu, h); 1829 - if (ret) 1830 - return ret; 1831 - 1832 1645 if (amd_iommu_irq_remap) { 1833 1646 ret = amd_iommu_create_irq_domain(iommu); 1834 1647 if (ret) ··· 1835 1656 * Make sure IOMMU is not considered to translate itself. The IVRS 1836 1657 * table tells us so, but this is a lie! 1837 1658 */ 1838 - amd_iommu_rlookup_table[iommu->devid] = NULL; 1659 + iommu->pci_seg->rlookup_table[iommu->devid] = NULL; 1839 1660 1840 1661 return 0; 1841 1662 } ··· 1880 1701 end += table->length; 1881 1702 p += IVRS_HEADER_LENGTH; 1882 1703 1704 + /* Phase 1: Process all IVHD blocks */ 1883 1705 while (p < end) { 1884 1706 h = (struct ivhd_header *)p; 1885 1707 if (*p == amd_iommu_target_ivhd_type) { 1886 1708 1887 - DUMP_printk("device: %02x:%02x.%01x cap: %04x " 1888 - "seg: %d flags: %01x info %04x\n", 1889 - PCI_BUS_NUM(h->devid), PCI_SLOT(h->devid), 1890 - PCI_FUNC(h->devid), h->cap_ptr, 1891 - h->pci_seg, h->flags, h->info); 1709 + DUMP_printk("device: %04x:%02x:%02x.%01x cap: %04x " 1710 + "flags: %01x info %04x\n", 1711 + h->pci_seg, PCI_BUS_NUM(h->devid), 1712 + PCI_SLOT(h->devid), PCI_FUNC(h->devid), 1713 + h->cap_ptr, h->flags, h->info); 1892 1714 DUMP_printk(" mmio-addr: %016llx\n", 1893 1715 h->mmio_phys); 1894 1716 ··· 1897 1717 if (iommu == NULL) 1898 1718 return -ENOMEM; 1899 1719 1900 - ret = init_iommu_one(iommu, h); 1720 + ret = init_iommu_one(iommu, h, table); 1901 1721 if (ret) 1902 1722 return ret; 1903 1723 } ··· 1905 1725 1906 1726 } 1907 1727 WARN_ON(p != end); 1728 + 1729 + /* Phase 2 : Early feature support check */ 1730 + get_global_efr(); 1731 + 1732 + /* Phase 3 : Enabling IOMMU features */ 1733 + for_each_iommu(iommu) { 1734 + ret = init_iommu_one_late(iommu); 1735 + if (ret) 1736 + return ret; 1737 + } 1908 1738 1909 1739 return 0; 1910 1740 } ··· 1952 1762 char *buf) 1953 1763 { 1954 1764 struct amd_iommu *iommu = dev_to_amd_iommu(dev); 1955 - return sprintf(buf, "%llx\n", iommu->features); 1765 + return sprintf(buf, "%llx:%llx\n", iommu->features2, iommu->features); 1956 1766 } 1957 1767 static DEVICE_ATTR(features, S_IRUGO, amd_iommu_show_features, NULL); 1958 1768 ··· 1979 1789 */ 1980 1790 static void __init late_iommu_features_init(struct amd_iommu *iommu) 1981 1791 { 1982 - u64 features; 1792 + u64 features, features2; 1983 1793 1984 1794 if (!(iommu->cap & (1 << IOMMU_CAP_EFR))) 1985 1795 return; 1986 1796 1987 1797 /* read extended feature bits */ 1988 1798 features = readq(iommu->mmio_base + MMIO_EXT_FEATURES); 1799 + features2 = readq(iommu->mmio_base + MMIO_EXT_FEATURES2); 1989 1800 1990 1801 if (!iommu->features) { 1991 1802 iommu->features = features; 1803 + iommu->features2 = features2; 1992 1804 return; 1993 1805 } 1994 1806 ··· 1998 1806 * Sanity check and warn if EFR values from 1999 1807 * IVHD and MMIO conflict. 2000 1808 */ 2001 - if (features != iommu->features) 2002 - pr_warn(FW_WARN "EFR mismatch. Use IVHD EFR (%#llx : %#llx).\n", 2003 - features, iommu->features); 1809 + if (features != iommu->features || 1810 + features2 != iommu->features2) { 1811 + pr_warn(FW_WARN 1812 + "EFR mismatch. Use IVHD EFR (%#llx : %#llx), EFR2 (%#llx : %#llx).\n", 1813 + features, iommu->features, 1814 + features2, iommu->features2); 1815 + } 2004 1816 } 2005 1817 2006 1818 static int __init iommu_init_pci(struct amd_iommu *iommu) ··· 2012 1816 int cap_ptr = iommu->cap_ptr; 2013 1817 int ret; 2014 1818 2015 - iommu->dev = pci_get_domain_bus_and_slot(0, PCI_BUS_NUM(iommu->devid), 1819 + iommu->dev = pci_get_domain_bus_and_slot(iommu->pci_seg->id, 1820 + PCI_BUS_NUM(iommu->devid), 2016 1821 iommu->devid & 0xff); 2017 1822 if (!iommu->dev) 2018 1823 return -ENODEV; ··· 2060 1863 if (iommu_feature(iommu, FEATURE_PPR) && alloc_ppr_log(iommu)) 2061 1864 return -ENOMEM; 2062 1865 2063 - ret = iommu_init_ga_log(iommu); 2064 - if (ret) 2065 - return ret; 2066 - 2067 1866 if (iommu->cap & (1UL << IOMMU_CAP_NPCACHE)) { 2068 1867 pr_info("Using strict mode due to virtualization\n"); 2069 1868 iommu_set_dma_strict(); ··· 2072 1879 int i, j; 2073 1880 2074 1881 iommu->root_pdev = 2075 - pci_get_domain_bus_and_slot(0, iommu->dev->bus->number, 1882 + pci_get_domain_bus_and_slot(iommu->pci_seg->id, 1883 + iommu->dev->bus->number, 2076 1884 PCI_DEVFN(0, 0)); 2077 1885 2078 1886 /* ··· 2100 1906 amd_iommu_erratum_746_workaround(iommu); 2101 1907 amd_iommu_ats_write_check_workaround(iommu); 2102 1908 2103 - iommu_device_sysfs_add(&iommu->iommu, &iommu->dev->dev, 1909 + ret = iommu_device_sysfs_add(&iommu->iommu, &iommu->dev->dev, 2104 1910 amd_iommu_groups, "ivhd%d", iommu->index); 1911 + if (ret) 1912 + return ret; 1913 + 2105 1914 iommu_device_register(&iommu->iommu, &amd_iommu_ops, NULL); 2106 1915 2107 1916 return pci_enable_device(iommu->dev); ··· 2125 1928 pci_info(pdev, "Found IOMMU cap 0x%x\n", iommu->cap_ptr); 2126 1929 2127 1930 if (iommu->cap & (1 << IOMMU_CAP_EFR)) { 2128 - pr_info("Extended features (%#llx):", iommu->features); 1931 + pr_info("Extended features (%#llx, %#llx):", iommu->features, iommu->features2); 2129 1932 2130 1933 for (i = 0; i < ARRAY_SIZE(feat_str); ++i) { 2131 1934 if (iommu_feature(iommu, (1ULL << i))) ··· 2135 1938 if (iommu->features & FEATURE_GAM_VAPIC) 2136 1939 pr_cont(" GA_vAPIC"); 2137 1940 1941 + if (iommu->features & FEATURE_SNP) 1942 + pr_cont(" SNP"); 1943 + 2138 1944 pr_cont("\n"); 2139 1945 } 2140 1946 } 2141 1947 if (irq_remapping_enabled) { 2142 1948 pr_info("Interrupt remapping enabled\n"); 2143 - if (AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir)) 2144 - pr_info("Virtual APIC enabled\n"); 2145 1949 if (amd_iommu_xt_mode == IRQ_REMAP_X2APIC_MODE) 2146 1950 pr_info("X2APIC enabled\n"); 2147 1951 } ··· 2151 1953 static int __init amd_iommu_init_pci(void) 2152 1954 { 2153 1955 struct amd_iommu *iommu; 1956 + struct amd_iommu_pci_seg *pci_seg; 2154 1957 int ret; 2155 1958 2156 1959 for_each_iommu(iommu) { ··· 2182 1983 goto out; 2183 1984 } 2184 1985 2185 - init_device_table_dma(); 1986 + for_each_pci_segment(pci_seg) 1987 + init_device_table_dma(pci_seg); 2186 1988 2187 1989 for_each_iommu(iommu) 2188 1990 iommu_flush_all_caches(iommu); ··· 2432 2232 2433 2233 if (iommu->ppr_log != NULL) 2434 2234 iommu_feature_enable(iommu, CONTROL_PPRINT_EN); 2435 - 2436 - iommu_ga_log_enable(iommu); 2437 - 2438 2235 return 0; 2439 2236 } 2440 2237 ··· 2446 2249 static void __init free_unity_maps(void) 2447 2250 { 2448 2251 struct unity_map_entry *entry, *next; 2252 + struct amd_iommu_pci_seg *p, *pci_seg; 2449 2253 2450 - list_for_each_entry_safe(entry, next, &amd_iommu_unity_map, list) { 2451 - list_del(&entry->list); 2452 - kfree(entry); 2254 + for_each_pci_segment_safe(pci_seg, p) { 2255 + list_for_each_entry_safe(entry, next, &pci_seg->unity_map, list) { 2256 + list_del(&entry->list); 2257 + kfree(entry); 2258 + } 2453 2259 } 2454 2260 } 2455 2261 2456 2262 /* called for unity map ACPI definition */ 2457 - static int __init init_unity_map_range(struct ivmd_header *m) 2263 + static int __init init_unity_map_range(struct ivmd_header *m, 2264 + struct acpi_table_header *ivrs_base) 2458 2265 { 2459 2266 struct unity_map_entry *e = NULL; 2267 + struct amd_iommu_pci_seg *pci_seg; 2460 2268 char *s; 2269 + 2270 + pci_seg = get_pci_segment(m->pci_seg, ivrs_base); 2271 + if (pci_seg == NULL) 2272 + return -ENOMEM; 2461 2273 2462 2274 e = kzalloc(sizeof(*e), GFP_KERNEL); 2463 2275 if (e == NULL) ··· 2483 2277 case ACPI_IVMD_TYPE_ALL: 2484 2278 s = "IVMD_TYPE_ALL\t\t"; 2485 2279 e->devid_start = 0; 2486 - e->devid_end = amd_iommu_last_bdf; 2280 + e->devid_end = pci_seg->last_bdf; 2487 2281 break; 2488 2282 case ACPI_IVMD_TYPE_RANGE: 2489 2283 s = "IVMD_TYPE_RANGE\t\t"; ··· 2505 2299 if (m->flags & IVMD_FLAG_EXCL_RANGE) 2506 2300 e->prot = (IVMD_FLAG_IW | IVMD_FLAG_IR) >> 1; 2507 2301 2508 - DUMP_printk("%s devid_start: %02x:%02x.%x devid_end: %02x:%02x.%x" 2509 - " range_start: %016llx range_end: %016llx flags: %x\n", s, 2302 + DUMP_printk("%s devid_start: %04x:%02x:%02x.%x devid_end: " 2303 + "%04x:%02x:%02x.%x range_start: %016llx range_end: %016llx" 2304 + " flags: %x\n", s, m->pci_seg, 2510 2305 PCI_BUS_NUM(e->devid_start), PCI_SLOT(e->devid_start), 2511 - PCI_FUNC(e->devid_start), PCI_BUS_NUM(e->devid_end), 2306 + PCI_FUNC(e->devid_start), m->pci_seg, 2307 + PCI_BUS_NUM(e->devid_end), 2512 2308 PCI_SLOT(e->devid_end), PCI_FUNC(e->devid_end), 2513 2309 e->address_start, e->address_end, m->flags); 2514 2310 2515 - list_add_tail(&e->list, &amd_iommu_unity_map); 2311 + list_add_tail(&e->list, &pci_seg->unity_map); 2516 2312 2517 2313 return 0; 2518 2314 } ··· 2531 2323 while (p < end) { 2532 2324 m = (struct ivmd_header *)p; 2533 2325 if (m->flags & (IVMD_FLAG_UNITY_MAP | IVMD_FLAG_EXCL_RANGE)) 2534 - init_unity_map_range(m); 2326 + init_unity_map_range(m, table); 2535 2327 2536 2328 p += m->length; 2537 2329 } ··· 2542 2334 /* 2543 2335 * Init the device table to not allow DMA access for devices 2544 2336 */ 2545 - static void init_device_table_dma(void) 2337 + static void init_device_table_dma(struct amd_iommu_pci_seg *pci_seg) 2546 2338 { 2547 2339 u32 devid; 2340 + struct dev_table_entry *dev_table = pci_seg->dev_table; 2548 2341 2549 - for (devid = 0; devid <= amd_iommu_last_bdf; ++devid) { 2550 - set_dev_entry_bit(devid, DEV_ENTRY_VALID); 2551 - set_dev_entry_bit(devid, DEV_ENTRY_TRANSLATION); 2342 + if (dev_table == NULL) 2343 + return; 2344 + 2345 + for (devid = 0; devid <= pci_seg->last_bdf; ++devid) { 2346 + __set_dev_entry_bit(dev_table, devid, DEV_ENTRY_VALID); 2347 + if (!amd_iommu_snp_en) 2348 + __set_dev_entry_bit(dev_table, devid, DEV_ENTRY_TRANSLATION); 2552 2349 } 2553 2350 } 2554 2351 2555 - static void __init uninit_device_table_dma(void) 2352 + static void __init uninit_device_table_dma(struct amd_iommu_pci_seg *pci_seg) 2556 2353 { 2557 2354 u32 devid; 2355 + struct dev_table_entry *dev_table = pci_seg->dev_table; 2558 2356 2559 - for (devid = 0; devid <= amd_iommu_last_bdf; ++devid) { 2560 - amd_iommu_dev_table[devid].data[0] = 0ULL; 2561 - amd_iommu_dev_table[devid].data[1] = 0ULL; 2357 + if (dev_table == NULL) 2358 + return; 2359 + 2360 + for (devid = 0; devid <= pci_seg->last_bdf; ++devid) { 2361 + dev_table[devid].data[0] = 0ULL; 2362 + dev_table[devid].data[1] = 0ULL; 2562 2363 } 2563 2364 } 2564 2365 2565 2366 static void init_device_table(void) 2566 2367 { 2368 + struct amd_iommu_pci_seg *pci_seg; 2567 2369 u32 devid; 2568 2370 2569 2371 if (!amd_iommu_irq_remap) 2570 2372 return; 2571 2373 2572 - for (devid = 0; devid <= amd_iommu_last_bdf; ++devid) 2573 - set_dev_entry_bit(devid, DEV_ENTRY_IRQ_TBL_EN); 2374 + for_each_pci_segment(pci_seg) { 2375 + for (devid = 0; devid <= pci_seg->last_bdf; ++devid) 2376 + __set_dev_entry_bit(pci_seg->dev_table, 2377 + devid, DEV_ENTRY_IRQ_TBL_EN); 2378 + } 2574 2379 } 2575 2380 2576 2381 static void iommu_init_flags(struct amd_iommu *iommu) ··· 2661 2440 #ifdef CONFIG_IRQ_REMAP 2662 2441 switch (amd_iommu_guest_ir) { 2663 2442 case AMD_IOMMU_GUEST_IR_VAPIC: 2664 - iommu_feature_enable(iommu, CONTROL_GAM_EN); 2665 - fallthrough; 2666 2443 case AMD_IOMMU_GUEST_IR_LEGACY_GA: 2667 2444 iommu_feature_enable(iommu, CONTROL_GA_EN); 2668 2445 iommu->irte_ops = &irte_128_ops; ··· 2697 2478 static void early_enable_iommus(void) 2698 2479 { 2699 2480 struct amd_iommu *iommu; 2700 - 2481 + struct amd_iommu_pci_seg *pci_seg; 2701 2482 2702 2483 if (!copy_device_table()) { 2703 2484 /* ··· 2707 2488 */ 2708 2489 if (amd_iommu_pre_enabled) 2709 2490 pr_err("Failed to copy DEV table from previous kernel.\n"); 2710 - if (old_dev_tbl_cpy != NULL) 2711 - free_pages((unsigned long)old_dev_tbl_cpy, 2712 - get_order(dev_table_size)); 2491 + 2492 + for_each_pci_segment(pci_seg) { 2493 + if (pci_seg->old_dev_tbl_cpy != NULL) { 2494 + free_pages((unsigned long)pci_seg->old_dev_tbl_cpy, 2495 + get_order(pci_seg->dev_table_size)); 2496 + pci_seg->old_dev_tbl_cpy = NULL; 2497 + } 2498 + } 2713 2499 2714 2500 for_each_iommu(iommu) { 2715 2501 clear_translation_pre_enabled(iommu); ··· 2722 2498 } 2723 2499 } else { 2724 2500 pr_info("Copied DEV table from previous kernel.\n"); 2725 - free_pages((unsigned long)amd_iommu_dev_table, 2726 - get_order(dev_table_size)); 2727 - amd_iommu_dev_table = old_dev_tbl_cpy; 2501 + 2502 + for_each_pci_segment(pci_seg) { 2503 + free_pages((unsigned long)pci_seg->dev_table, 2504 + get_order(pci_seg->dev_table_size)); 2505 + pci_seg->dev_table = pci_seg->old_dev_tbl_cpy; 2506 + } 2507 + 2728 2508 for_each_iommu(iommu) { 2729 2509 iommu_disable_command_buffer(iommu); 2730 2510 iommu_disable_event_buffer(iommu); ··· 2740 2512 iommu_flush_all_caches(iommu); 2741 2513 } 2742 2514 } 2743 - 2744 - #ifdef CONFIG_IRQ_REMAP 2745 - /* 2746 - * Note: We have already checked GASup from IVRS table. 2747 - * Now, we need to make sure that GAMSup is set. 2748 - */ 2749 - if (AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir) && 2750 - !check_feature_on_all_iommus(FEATURE_GAM_VAPIC)) 2751 - amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_LEGACY_GA; 2752 - 2753 - if (AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir)) 2754 - amd_iommu_irq_ops.capability |= (1 << IRQ_POSTING_CAP); 2755 - #endif 2756 2515 } 2757 2516 2758 2517 static void enable_iommus_v2(void) ··· 2752 2537 } 2753 2538 } 2754 2539 2540 + static void enable_iommus_vapic(void) 2541 + { 2542 + #ifdef CONFIG_IRQ_REMAP 2543 + u32 status, i; 2544 + struct amd_iommu *iommu; 2545 + 2546 + for_each_iommu(iommu) { 2547 + /* 2548 + * Disable GALog if already running. It could have been enabled 2549 + * in the previous boot before kdump. 2550 + */ 2551 + status = readl(iommu->mmio_base + MMIO_STATUS_OFFSET); 2552 + if (!(status & MMIO_STATUS_GALOG_RUN_MASK)) 2553 + continue; 2554 + 2555 + iommu_feature_disable(iommu, CONTROL_GALOG_EN); 2556 + iommu_feature_disable(iommu, CONTROL_GAINT_EN); 2557 + 2558 + /* 2559 + * Need to set and poll check the GALOGRun bit to zero before 2560 + * we can set/ modify GA Log registers safely. 2561 + */ 2562 + for (i = 0; i < LOOP_TIMEOUT; ++i) { 2563 + status = readl(iommu->mmio_base + MMIO_STATUS_OFFSET); 2564 + if (!(status & MMIO_STATUS_GALOG_RUN_MASK)) 2565 + break; 2566 + udelay(10); 2567 + } 2568 + 2569 + if (WARN_ON(i >= LOOP_TIMEOUT)) 2570 + return; 2571 + } 2572 + 2573 + if (AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir) && 2574 + !check_feature_on_all_iommus(FEATURE_GAM_VAPIC)) { 2575 + amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_LEGACY_GA; 2576 + return; 2577 + } 2578 + 2579 + if (amd_iommu_snp_en && 2580 + !FEATURE_SNPAVICSUP_GAM(amd_iommu_efr2)) { 2581 + pr_warn("Force to disable Virtual APIC due to SNP\n"); 2582 + amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_LEGACY_GA; 2583 + return; 2584 + } 2585 + 2586 + /* Enabling GAM and SNPAVIC support */ 2587 + for_each_iommu(iommu) { 2588 + if (iommu_init_ga_log(iommu) || 2589 + iommu_ga_log_enable(iommu)) 2590 + return; 2591 + 2592 + iommu_feature_enable(iommu, CONTROL_GAM_EN); 2593 + if (amd_iommu_snp_en) 2594 + iommu_feature_enable(iommu, CONTROL_SNPAVIC_EN); 2595 + } 2596 + 2597 + amd_iommu_irq_ops.capability |= (1 << IRQ_POSTING_CAP); 2598 + pr_info("Virtual APIC enabled\n"); 2599 + #endif 2600 + } 2601 + 2755 2602 static void enable_iommus(void) 2756 2603 { 2757 2604 early_enable_iommus(); 2758 - 2605 + enable_iommus_vapic(); 2759 2606 enable_iommus_v2(); 2760 2607 } 2761 2608 ··· 2867 2590 2868 2591 static void __init free_iommu_resources(void) 2869 2592 { 2870 - kmemleak_free(irq_lookup_table); 2871 - free_pages((unsigned long)irq_lookup_table, 2872 - get_order(rlookup_table_size)); 2873 - irq_lookup_table = NULL; 2874 - 2875 2593 kmem_cache_destroy(amd_iommu_irq_cache); 2876 2594 amd_iommu_irq_cache = NULL; 2877 2595 2878 - free_pages((unsigned long)amd_iommu_rlookup_table, 2879 - get_order(rlookup_table_size)); 2880 - amd_iommu_rlookup_table = NULL; 2881 - 2882 - free_pages((unsigned long)amd_iommu_alias_table, 2883 - get_order(alias_table_size)); 2884 - amd_iommu_alias_table = NULL; 2885 - 2886 - free_pages((unsigned long)amd_iommu_dev_table, 2887 - get_order(dev_table_size)); 2888 - amd_iommu_dev_table = NULL; 2889 - 2890 2596 free_iommu_all(); 2597 + free_pci_segments(); 2891 2598 } 2892 2599 2893 2600 /* SB IOAPIC is always on this device in AMD systems */ ··· 2970 2709 static int __init early_amd_iommu_init(void) 2971 2710 { 2972 2711 struct acpi_table_header *ivrs_base; 2973 - int i, remap_cache_sz, ret; 2712 + int remap_cache_sz, ret; 2974 2713 acpi_status status; 2975 2714 2976 2715 if (!amd_iommu_detected) ··· 2998 2737 amd_iommu_target_ivhd_type = get_highest_supported_ivhd_type(ivrs_base); 2999 2738 DUMP_printk("Using IVHD type %#x\n", amd_iommu_target_ivhd_type); 3000 2739 3001 - /* 3002 - * First parse ACPI tables to find the largest Bus/Dev/Func 3003 - * we need to handle. Upon this information the shared data 3004 - * structures for the IOMMUs in the system will be allocated 3005 - */ 3006 - ret = find_last_devid_acpi(ivrs_base); 3007 - if (ret) 3008 - goto out; 3009 - 3010 - dev_table_size = tbl_size(DEV_TABLE_ENTRY_SIZE); 3011 - alias_table_size = tbl_size(ALIAS_TABLE_ENTRY_SIZE); 3012 - rlookup_table_size = tbl_size(RLOOKUP_TABLE_ENTRY_SIZE); 3013 - 3014 2740 /* Device table - directly used by all IOMMUs */ 3015 2741 ret = -ENOMEM; 3016 - amd_iommu_dev_table = (void *)__get_free_pages( 3017 - GFP_KERNEL | __GFP_ZERO | GFP_DMA32, 3018 - get_order(dev_table_size)); 3019 - if (amd_iommu_dev_table == NULL) 3020 - goto out; 3021 - 3022 - /* 3023 - * Alias table - map PCI Bus/Dev/Func to Bus/Dev/Func the 3024 - * IOMMU see for that device 3025 - */ 3026 - amd_iommu_alias_table = (void *)__get_free_pages(GFP_KERNEL, 3027 - get_order(alias_table_size)); 3028 - if (amd_iommu_alias_table == NULL) 3029 - goto out; 3030 - 3031 - /* IOMMU rlookup table - find the IOMMU for a specific device */ 3032 - amd_iommu_rlookup_table = (void *)__get_free_pages( 3033 - GFP_KERNEL | __GFP_ZERO, 3034 - get_order(rlookup_table_size)); 3035 - if (amd_iommu_rlookup_table == NULL) 3036 - goto out; 3037 2742 3038 2743 amd_iommu_pd_alloc_bitmap = (void *)__get_free_pages( 3039 2744 GFP_KERNEL | __GFP_ZERO, 3040 2745 get_order(MAX_DOMAIN_ID/8)); 3041 2746 if (amd_iommu_pd_alloc_bitmap == NULL) 3042 2747 goto out; 3043 - 3044 - /* 3045 - * let all alias entries point to itself 3046 - */ 3047 - for (i = 0; i <= amd_iommu_last_bdf; ++i) 3048 - amd_iommu_alias_table[i] = i; 3049 2748 3050 2749 /* 3051 2750 * never allocate domain 0 because its used as the non-allocated and ··· 3029 2808 amd_iommu_irq_remap = check_ioapic_information(); 3030 2809 3031 2810 if (amd_iommu_irq_remap) { 2811 + struct amd_iommu_pci_seg *pci_seg; 3032 2812 /* 3033 2813 * Interrupt remapping enabled, create kmem_cache for the 3034 2814 * remapping tables. ··· 3046 2824 if (!amd_iommu_irq_cache) 3047 2825 goto out; 3048 2826 3049 - irq_lookup_table = (void *)__get_free_pages( 3050 - GFP_KERNEL | __GFP_ZERO, 3051 - get_order(rlookup_table_size)); 3052 - kmemleak_alloc(irq_lookup_table, rlookup_table_size, 3053 - 1, GFP_KERNEL); 3054 - if (!irq_lookup_table) 3055 - goto out; 2827 + for_each_pci_segment(pci_seg) { 2828 + if (alloc_irq_lookup_table(pci_seg)) 2829 + goto out; 2830 + } 3056 2831 } 3057 2832 3058 2833 ret = init_memory_definitions(ivrs_base); ··· 3156 2937 register_syscore_ops(&amd_iommu_syscore_ops); 3157 2938 ret = amd_iommu_init_pci(); 3158 2939 init_state = ret ? IOMMU_INIT_ERROR : IOMMU_PCI_INIT; 2940 + enable_iommus_vapic(); 3159 2941 enable_iommus_v2(); 3160 2942 break; 3161 2943 case IOMMU_PCI_INIT: ··· 3187 2967 free_iommu_resources(); 3188 2968 } else { 3189 2969 struct amd_iommu *iommu; 2970 + struct amd_iommu_pci_seg *pci_seg; 3190 2971 3191 - uninit_device_table_dma(); 2972 + for_each_pci_segment(pci_seg) 2973 + uninit_device_table_dma(pci_seg); 2974 + 3192 2975 for_each_iommu(iommu) 3193 2976 iommu_flush_all_caches(iommu); 3194 2977 } ··· 3384 3161 3385 3162 static int __init parse_ivrs_ioapic(char *str) 3386 3163 { 3387 - unsigned int bus, dev, fn; 3164 + u32 seg = 0, bus, dev, fn; 3388 3165 int ret, id, i; 3389 - u16 devid; 3166 + u32 devid; 3390 3167 3391 3168 ret = sscanf(str, "[%d]=%x:%x.%x", &id, &bus, &dev, &fn); 3392 - 3393 3169 if (ret != 4) { 3394 - pr_err("Invalid command line: ivrs_ioapic%s\n", str); 3395 - return 1; 3170 + ret = sscanf(str, "[%d]=%x:%x:%x.%x", &id, &seg, &bus, &dev, &fn); 3171 + if (ret != 5) { 3172 + pr_err("Invalid command line: ivrs_ioapic%s\n", str); 3173 + return 1; 3174 + } 3396 3175 } 3397 3176 3398 3177 if (early_ioapic_map_size == EARLY_MAP_SIZE) { ··· 3403 3178 return 1; 3404 3179 } 3405 3180 3406 - devid = ((bus & 0xff) << 8) | ((dev & 0x1f) << 3) | (fn & 0x7); 3181 + devid = IVRS_GET_SBDF_ID(seg, bus, dev, fn); 3407 3182 3408 3183 cmdline_maps = true; 3409 3184 i = early_ioapic_map_size++; ··· 3416 3191 3417 3192 static int __init parse_ivrs_hpet(char *str) 3418 3193 { 3419 - unsigned int bus, dev, fn; 3194 + u32 seg = 0, bus, dev, fn; 3420 3195 int ret, id, i; 3421 - u16 devid; 3196 + u32 devid; 3422 3197 3423 3198 ret = sscanf(str, "[%d]=%x:%x.%x", &id, &bus, &dev, &fn); 3424 - 3425 3199 if (ret != 4) { 3426 - pr_err("Invalid command line: ivrs_hpet%s\n", str); 3427 - return 1; 3200 + ret = sscanf(str, "[%d]=%x:%x:%x.%x", &id, &seg, &bus, &dev, &fn); 3201 + if (ret != 5) { 3202 + pr_err("Invalid command line: ivrs_hpet%s\n", str); 3203 + return 1; 3204 + } 3428 3205 } 3429 3206 3430 3207 if (early_hpet_map_size == EARLY_MAP_SIZE) { ··· 3435 3208 return 1; 3436 3209 } 3437 3210 3438 - devid = ((bus & 0xff) << 8) | ((dev & 0x1f) << 3) | (fn & 0x7); 3211 + devid = IVRS_GET_SBDF_ID(seg, bus, dev, fn); 3439 3212 3440 3213 cmdline_maps = true; 3441 3214 i = early_hpet_map_size++; ··· 3448 3221 3449 3222 static int __init parse_ivrs_acpihid(char *str) 3450 3223 { 3451 - u32 bus, dev, fn; 3224 + u32 seg = 0, bus, dev, fn; 3452 3225 char *hid, *uid, *p; 3453 3226 char acpiid[ACPIHID_UID_LEN + ACPIHID_HID_LEN] = {0}; 3454 3227 int ret, i; 3455 3228 3456 3229 ret = sscanf(str, "[%x:%x.%x]=%s", &bus, &dev, &fn, acpiid); 3457 3230 if (ret != 4) { 3458 - pr_err("Invalid command line: ivrs_acpihid(%s)\n", str); 3459 - return 1; 3231 + ret = sscanf(str, "[%x:%x:%x.%x]=%s", &seg, &bus, &dev, &fn, acpiid); 3232 + if (ret != 5) { 3233 + pr_err("Invalid command line: ivrs_acpihid(%s)\n", str); 3234 + return 1; 3235 + } 3460 3236 } 3461 3237 3462 3238 p = acpiid; ··· 3474 3244 i = early_acpihid_map_size++; 3475 3245 memcpy(early_acpihid_map[i].hid, hid, strlen(hid)); 3476 3246 memcpy(early_acpihid_map[i].uid, uid, strlen(uid)); 3477 - early_acpihid_map[i].devid = 3478 - ((bus & 0xff) << 8) | ((dev & 0x1f) << 3) | (fn & 0x7); 3247 + early_acpihid_map[i].devid = IVRS_GET_SBDF_ID(seg, bus, dev, fn); 3479 3248 early_acpihid_map[i].cmd_line = true; 3480 3249 3481 3250 return 1; ··· 3489 3260 3490 3261 bool amd_iommu_v2_supported(void) 3491 3262 { 3492 - return amd_iommu_v2_present; 3263 + /* 3264 + * Since DTE[Mode]=0 is prohibited on SNP-enabled system 3265 + * (i.e. EFR[SNPSup]=1), IOMMUv2 page table cannot be used without 3266 + * setting up IOMMUv1 page table. 3267 + */ 3268 + return amd_iommu_v2_present && !amd_iommu_snp_en; 3493 3269 } 3494 3270 EXPORT_SYMBOL(amd_iommu_v2_supported); 3495 3271 ··· 3597 3363 3598 3364 return iommu_pc_get_set_reg(iommu, bank, cntr, fxn, value, true); 3599 3365 } 3366 + 3367 + #ifdef CONFIG_AMD_MEM_ENCRYPT 3368 + int amd_iommu_snp_enable(void) 3369 + { 3370 + /* 3371 + * The SNP support requires that IOMMU must be enabled, and is 3372 + * not configured in the passthrough mode. 3373 + */ 3374 + if (no_iommu || iommu_default_passthrough()) { 3375 + pr_err("SNP: IOMMU is disabled or configured in passthrough mode, SNP cannot be supported"); 3376 + return -EINVAL; 3377 + } 3378 + 3379 + /* 3380 + * Prevent enabling SNP after IOMMU_ENABLED state because this process 3381 + * affect how IOMMU driver sets up data structures and configures 3382 + * IOMMU hardware. 3383 + */ 3384 + if (init_state > IOMMU_ENABLED) { 3385 + pr_err("SNP: Too late to enable SNP for IOMMU.\n"); 3386 + return -EINVAL; 3387 + } 3388 + 3389 + amd_iommu_snp_en = check_feature_on_all_iommus(FEATURE_SNP); 3390 + if (!amd_iommu_snp_en) 3391 + return -EINVAL; 3392 + 3393 + pr_info("SNP enabled\n"); 3394 + 3395 + /* Enforce IOMMU v1 pagetable when SNP is enabled. */ 3396 + if (amd_iommu_pgtable != AMD_IOMMU_V1) { 3397 + pr_warn("Force to using AMD IOMMU v1 page table due to SNP\n"); 3398 + amd_iommu_pgtable = AMD_IOMMU_V1; 3399 + } 3400 + 3401 + return 0; 3402 + } 3403 + #endif
+2 -4
drivers/iommu/amd/io_pgtable.c
··· 258 258 __npte = PM_LEVEL_PDE(level, iommu_virt_to_phys(page)); 259 259 260 260 /* pte could have been changed somewhere. */ 261 - if (cmpxchg64(pte, __pte, __npte) != __pte) 261 + if (!try_cmpxchg64(pte, &__pte, __npte)) 262 262 free_page((unsigned long)page); 263 263 else if (IOMMU_PTE_PRESENT(__pte)) 264 264 *updated = true; ··· 341 341 u64 *pt; 342 342 int mode; 343 343 344 - while (cmpxchg64(pte, pteval, 0) != pteval) { 344 + while (!try_cmpxchg64(pte, &pteval, 0)) 345 345 pr_warn("AMD-Vi: IOMMU pte changed since we read it\n"); 346 - pteval = *pte; 347 - } 348 346 349 347 if (!IOMMU_PTE_PRESENT(pteval)) 350 348 return;
+351 -238
drivers/iommu/amd/iommu.c
··· 62 62 63 63 static DEFINE_SPINLOCK(pd_bitmap_lock); 64 64 65 - /* List of all available dev_data structures */ 66 - static LLIST_HEAD(dev_data_list); 67 - 68 65 LIST_HEAD(ioapic_map); 69 66 LIST_HEAD(hpet_map); 70 67 LIST_HEAD(acpihid_map); ··· 92 95 * 93 96 ****************************************************************************/ 94 97 95 - static inline u16 get_pci_device_id(struct device *dev) 96 - { 97 - struct pci_dev *pdev = to_pci_dev(dev); 98 - 99 - return pci_dev_id(pdev); 100 - } 101 - 102 98 static inline int get_acpihid_device_id(struct device *dev, 103 99 struct acpihid_map_entry **entry) 104 100 { ··· 112 122 return -EINVAL; 113 123 } 114 124 115 - static inline int get_device_id(struct device *dev) 125 + static inline int get_device_sbdf_id(struct device *dev) 116 126 { 117 - int devid; 127 + int sbdf; 118 128 119 129 if (dev_is_pci(dev)) 120 - devid = get_pci_device_id(dev); 130 + sbdf = get_pci_sbdf_id(to_pci_dev(dev)); 121 131 else 122 - devid = get_acpihid_device_id(dev, NULL); 132 + sbdf = get_acpihid_device_id(dev, NULL); 123 133 124 - return devid; 134 + return sbdf; 135 + } 136 + 137 + struct dev_table_entry *get_dev_table(struct amd_iommu *iommu) 138 + { 139 + struct dev_table_entry *dev_table; 140 + struct amd_iommu_pci_seg *pci_seg = iommu->pci_seg; 141 + 142 + BUG_ON(pci_seg == NULL); 143 + dev_table = pci_seg->dev_table; 144 + BUG_ON(dev_table == NULL); 145 + 146 + return dev_table; 147 + } 148 + 149 + static inline u16 get_device_segment(struct device *dev) 150 + { 151 + u16 seg; 152 + 153 + if (dev_is_pci(dev)) { 154 + struct pci_dev *pdev = to_pci_dev(dev); 155 + 156 + seg = pci_domain_nr(pdev->bus); 157 + } else { 158 + u32 devid = get_acpihid_device_id(dev, NULL); 159 + 160 + seg = PCI_SBDF_TO_SEGID(devid); 161 + } 162 + 163 + return seg; 164 + } 165 + 166 + /* Writes the specific IOMMU for a device into the PCI segment rlookup table */ 167 + void amd_iommu_set_rlookup_table(struct amd_iommu *iommu, u16 devid) 168 + { 169 + struct amd_iommu_pci_seg *pci_seg = iommu->pci_seg; 170 + 171 + pci_seg->rlookup_table[devid] = iommu; 172 + } 173 + 174 + static struct amd_iommu *__rlookup_amd_iommu(u16 seg, u16 devid) 175 + { 176 + struct amd_iommu_pci_seg *pci_seg; 177 + 178 + for_each_pci_segment(pci_seg) { 179 + if (pci_seg->id == seg) 180 + return pci_seg->rlookup_table[devid]; 181 + } 182 + return NULL; 183 + } 184 + 185 + static struct amd_iommu *rlookup_amd_iommu(struct device *dev) 186 + { 187 + u16 seg = get_device_segment(dev); 188 + int devid = get_device_sbdf_id(dev); 189 + 190 + if (devid < 0) 191 + return NULL; 192 + return __rlookup_amd_iommu(seg, PCI_SBDF_TO_DEVID(devid)); 125 193 } 126 194 127 195 static struct protection_domain *to_pdomain(struct iommu_domain *dom) ··· 187 139 return container_of(dom, struct protection_domain, domain); 188 140 } 189 141 190 - static struct iommu_dev_data *alloc_dev_data(u16 devid) 142 + static struct iommu_dev_data *alloc_dev_data(struct amd_iommu *iommu, u16 devid) 191 143 { 192 144 struct iommu_dev_data *dev_data; 145 + struct amd_iommu_pci_seg *pci_seg = iommu->pci_seg; 193 146 194 147 dev_data = kzalloc(sizeof(*dev_data), GFP_KERNEL); 195 148 if (!dev_data) ··· 200 151 dev_data->devid = devid; 201 152 ratelimit_default_init(&dev_data->rs); 202 153 203 - llist_add(&dev_data->dev_data_list, &dev_data_list); 154 + llist_add(&dev_data->dev_data_list, &pci_seg->dev_data_list); 204 155 return dev_data; 205 156 } 206 157 207 - static struct iommu_dev_data *search_dev_data(u16 devid) 158 + static struct iommu_dev_data *search_dev_data(struct amd_iommu *iommu, u16 devid) 208 159 { 209 160 struct iommu_dev_data *dev_data; 210 161 struct llist_node *node; 162 + struct amd_iommu_pci_seg *pci_seg = iommu->pci_seg; 211 163 212 - if (llist_empty(&dev_data_list)) 164 + if (llist_empty(&pci_seg->dev_data_list)) 213 165 return NULL; 214 166 215 - node = dev_data_list.first; 167 + node = pci_seg->dev_data_list.first; 216 168 llist_for_each_entry(dev_data, node, dev_data_list) { 217 169 if (dev_data->devid == devid) 218 170 return dev_data; ··· 224 174 225 175 static int clone_alias(struct pci_dev *pdev, u16 alias, void *data) 226 176 { 177 + struct amd_iommu *iommu; 178 + struct dev_table_entry *dev_table; 227 179 u16 devid = pci_dev_id(pdev); 228 180 229 181 if (devid == alias) 230 182 return 0; 231 183 232 - amd_iommu_rlookup_table[alias] = 233 - amd_iommu_rlookup_table[devid]; 234 - memcpy(amd_iommu_dev_table[alias].data, 235 - amd_iommu_dev_table[devid].data, 236 - sizeof(amd_iommu_dev_table[alias].data)); 184 + iommu = rlookup_amd_iommu(&pdev->dev); 185 + if (!iommu) 186 + return 0; 187 + 188 + amd_iommu_set_rlookup_table(iommu, alias); 189 + dev_table = get_dev_table(iommu); 190 + memcpy(dev_table[alias].data, 191 + dev_table[devid].data, 192 + sizeof(dev_table[alias].data)); 237 193 238 194 return 0; 239 195 } 240 196 241 - static void clone_aliases(struct pci_dev *pdev) 197 + static void clone_aliases(struct amd_iommu *iommu, struct device *dev) 242 198 { 243 - if (!pdev) 199 + struct pci_dev *pdev; 200 + 201 + if (!dev_is_pci(dev)) 244 202 return; 203 + pdev = to_pci_dev(dev); 245 204 246 205 /* 247 206 * The IVRS alias stored in the alias table may not be 248 207 * part of the PCI DMA aliases if it's bus differs 249 208 * from the original device. 250 209 */ 251 - clone_alias(pdev, amd_iommu_alias_table[pci_dev_id(pdev)], NULL); 210 + clone_alias(pdev, iommu->pci_seg->alias_table[pci_dev_id(pdev)], NULL); 252 211 253 212 pci_for_each_dma_alias(pdev, clone_alias, NULL); 254 213 } 255 214 256 - static struct pci_dev *setup_aliases(struct device *dev) 215 + static void setup_aliases(struct amd_iommu *iommu, struct device *dev) 257 216 { 258 217 struct pci_dev *pdev = to_pci_dev(dev); 218 + struct amd_iommu_pci_seg *pci_seg = iommu->pci_seg; 259 219 u16 ivrs_alias; 260 220 261 221 /* For ACPI HID devices, there are no aliases */ 262 222 if (!dev_is_pci(dev)) 263 - return NULL; 223 + return; 264 224 265 225 /* 266 226 * Add the IVRS alias to the pci aliases if it is on the same 267 227 * bus. The IVRS table may know about a quirk that we don't. 268 228 */ 269 - ivrs_alias = amd_iommu_alias_table[pci_dev_id(pdev)]; 229 + ivrs_alias = pci_seg->alias_table[pci_dev_id(pdev)]; 270 230 if (ivrs_alias != pci_dev_id(pdev) && 271 231 PCI_BUS_NUM(ivrs_alias) == pdev->bus->number) 272 232 pci_add_dma_alias(pdev, ivrs_alias & 0xff, 1); 273 233 274 - clone_aliases(pdev); 275 - 276 - return pdev; 234 + clone_aliases(iommu, dev); 277 235 } 278 236 279 - static struct iommu_dev_data *find_dev_data(u16 devid) 237 + static struct iommu_dev_data *find_dev_data(struct amd_iommu *iommu, u16 devid) 280 238 { 281 239 struct iommu_dev_data *dev_data; 282 - struct amd_iommu *iommu = amd_iommu_rlookup_table[devid]; 283 240 284 - dev_data = search_dev_data(devid); 241 + dev_data = search_dev_data(iommu, devid); 285 242 286 243 if (dev_data == NULL) { 287 - dev_data = alloc_dev_data(devid); 244 + dev_data = alloc_dev_data(iommu, devid); 288 245 if (!dev_data) 289 246 return NULL; 290 247 ··· 353 296 */ 354 297 static bool check_device(struct device *dev) 355 298 { 356 - int devid; 299 + struct amd_iommu_pci_seg *pci_seg; 300 + struct amd_iommu *iommu; 301 + int devid, sbdf; 357 302 358 303 if (!dev) 359 304 return false; 360 305 361 - devid = get_device_id(dev); 362 - if (devid < 0) 306 + sbdf = get_device_sbdf_id(dev); 307 + if (sbdf < 0) 308 + return false; 309 + devid = PCI_SBDF_TO_DEVID(sbdf); 310 + 311 + iommu = rlookup_amd_iommu(dev); 312 + if (!iommu) 363 313 return false; 364 314 365 315 /* Out of our scope? */ 366 - if (devid > amd_iommu_last_bdf) 367 - return false; 368 - 369 - if (amd_iommu_rlookup_table[devid] == NULL) 316 + pci_seg = iommu->pci_seg; 317 + if (devid > pci_seg->last_bdf) 370 318 return false; 371 319 372 320 return true; 373 321 } 374 322 375 - static int iommu_init_device(struct device *dev) 323 + static int iommu_init_device(struct amd_iommu *iommu, struct device *dev) 376 324 { 377 325 struct iommu_dev_data *dev_data; 378 - int devid; 326 + int devid, sbdf; 379 327 380 328 if (dev_iommu_priv_get(dev)) 381 329 return 0; 382 330 383 - devid = get_device_id(dev); 384 - if (devid < 0) 385 - return devid; 331 + sbdf = get_device_sbdf_id(dev); 332 + if (sbdf < 0) 333 + return sbdf; 386 334 387 - dev_data = find_dev_data(devid); 335 + devid = PCI_SBDF_TO_DEVID(sbdf); 336 + dev_data = find_dev_data(iommu, devid); 388 337 if (!dev_data) 389 338 return -ENOMEM; 390 339 391 - dev_data->pdev = setup_aliases(dev); 340 + dev_data->dev = dev; 341 + setup_aliases(iommu, dev); 392 342 393 343 /* 394 344 * By default we use passthrough mode for IOMMUv2 capable device. ··· 405 341 */ 406 342 if ((iommu_default_passthrough() || !amd_iommu_force_isolation) && 407 343 dev_is_pci(dev) && pci_iommuv2_capable(to_pci_dev(dev))) { 408 - struct amd_iommu *iommu; 409 - 410 - iommu = amd_iommu_rlookup_table[dev_data->devid]; 411 344 dev_data->iommu_v2 = iommu->is_iommu_v2; 412 345 } 413 346 ··· 413 352 return 0; 414 353 } 415 354 416 - static void iommu_ignore_device(struct device *dev) 355 + static void iommu_ignore_device(struct amd_iommu *iommu, struct device *dev) 417 356 { 418 - int devid; 357 + struct amd_iommu_pci_seg *pci_seg = iommu->pci_seg; 358 + struct dev_table_entry *dev_table = get_dev_table(iommu); 359 + int devid, sbdf; 419 360 420 - devid = get_device_id(dev); 421 - if (devid < 0) 361 + sbdf = get_device_sbdf_id(dev); 362 + if (sbdf < 0) 422 363 return; 423 364 424 - amd_iommu_rlookup_table[devid] = NULL; 425 - memset(&amd_iommu_dev_table[devid], 0, sizeof(struct dev_table_entry)); 365 + devid = PCI_SBDF_TO_DEVID(sbdf); 366 + pci_seg->rlookup_table[devid] = NULL; 367 + memset(&dev_table[devid], 0, sizeof(struct dev_table_entry)); 426 368 427 - setup_aliases(dev); 369 + setup_aliases(iommu, dev); 428 370 } 429 371 430 372 static void amd_iommu_uninit_device(struct device *dev) ··· 455 391 * 456 392 ****************************************************************************/ 457 393 458 - static void dump_dte_entry(u16 devid) 394 + static void dump_dte_entry(struct amd_iommu *iommu, u16 devid) 459 395 { 460 396 int i; 397 + struct dev_table_entry *dev_table = get_dev_table(iommu); 461 398 462 399 for (i = 0; i < 4; ++i) 463 - pr_err("DTE[%d]: %016llx\n", i, 464 - amd_iommu_dev_table[devid].data[i]); 400 + pr_err("DTE[%d]: %016llx\n", i, dev_table[devid].data[i]); 465 401 } 466 402 467 403 static void dump_command(unsigned long phys_addr) ··· 473 409 pr_err("CMD[%d]: %08x\n", i, cmd->data[i]); 474 410 } 475 411 476 - static void amd_iommu_report_rmp_hw_error(volatile u32 *event) 412 + static void amd_iommu_report_rmp_hw_error(struct amd_iommu *iommu, volatile u32 *event) 477 413 { 478 414 struct iommu_dev_data *dev_data = NULL; 479 415 int devid, vmg_tag, flags; ··· 485 421 flags = (event[1] >> EVENT_FLAGS_SHIFT) & EVENT_FLAGS_MASK; 486 422 spa = ((u64)event[3] << 32) | (event[2] & 0xFFFFFFF8); 487 423 488 - pdev = pci_get_domain_bus_and_slot(0, PCI_BUS_NUM(devid), 424 + pdev = pci_get_domain_bus_and_slot(iommu->pci_seg->id, PCI_BUS_NUM(devid), 489 425 devid & 0xff); 490 426 if (pdev) 491 427 dev_data = dev_iommu_priv_get(&pdev->dev); ··· 496 432 vmg_tag, spa, flags); 497 433 } 498 434 } else { 499 - pr_err_ratelimited("Event logged [RMP_HW_ERROR device=%02x:%02x.%x, vmg_tag=0x%04x, spa=0x%llx, flags=0x%04x]\n", 500 - PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid), 435 + pr_err_ratelimited("Event logged [RMP_HW_ERROR device=%04x:%02x:%02x.%x, vmg_tag=0x%04x, spa=0x%llx, flags=0x%04x]\n", 436 + iommu->pci_seg->id, PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid), 501 437 vmg_tag, spa, flags); 502 438 } 503 439 ··· 505 441 pci_dev_put(pdev); 506 442 } 507 443 508 - static void amd_iommu_report_rmp_fault(volatile u32 *event) 444 + static void amd_iommu_report_rmp_fault(struct amd_iommu *iommu, volatile u32 *event) 509 445 { 510 446 struct iommu_dev_data *dev_data = NULL; 511 447 int devid, flags_rmp, vmg_tag, flags; ··· 518 454 flags = (event[1] >> EVENT_FLAGS_SHIFT) & EVENT_FLAGS_MASK; 519 455 gpa = ((u64)event[3] << 32) | event[2]; 520 456 521 - pdev = pci_get_domain_bus_and_slot(0, PCI_BUS_NUM(devid), 457 + pdev = pci_get_domain_bus_and_slot(iommu->pci_seg->id, PCI_BUS_NUM(devid), 522 458 devid & 0xff); 523 459 if (pdev) 524 460 dev_data = dev_iommu_priv_get(&pdev->dev); ··· 529 465 vmg_tag, gpa, flags_rmp, flags); 530 466 } 531 467 } else { 532 - pr_err_ratelimited("Event logged [RMP_PAGE_FAULT device=%02x:%02x.%x, vmg_tag=0x%04x, gpa=0x%llx, flags_rmp=0x%04x, flags=0x%04x]\n", 533 - PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid), 468 + pr_err_ratelimited("Event logged [RMP_PAGE_FAULT device=%04x:%02x:%02x.%x, vmg_tag=0x%04x, gpa=0x%llx, flags_rmp=0x%04x, flags=0x%04x]\n", 469 + iommu->pci_seg->id, PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid), 534 470 vmg_tag, gpa, flags_rmp, flags); 535 471 } 536 472 ··· 544 480 #define IS_WRITE_REQUEST(flags) \ 545 481 ((flags) & EVENT_FLAG_RW) 546 482 547 - static void amd_iommu_report_page_fault(u16 devid, u16 domain_id, 483 + static void amd_iommu_report_page_fault(struct amd_iommu *iommu, 484 + u16 devid, u16 domain_id, 548 485 u64 address, int flags) 549 486 { 550 487 struct iommu_dev_data *dev_data = NULL; 551 488 struct pci_dev *pdev; 552 489 553 - pdev = pci_get_domain_bus_and_slot(0, PCI_BUS_NUM(devid), 490 + pdev = pci_get_domain_bus_and_slot(iommu->pci_seg->id, PCI_BUS_NUM(devid), 554 491 devid & 0xff); 555 492 if (pdev) 556 493 dev_data = dev_iommu_priv_get(&pdev->dev); ··· 576 511 domain_id, address, flags); 577 512 } 578 513 } else { 579 - pr_err_ratelimited("Event logged [IO_PAGE_FAULT device=%02x:%02x.%x domain=0x%04x address=0x%llx flags=0x%04x]\n", 580 - PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid), 514 + pr_err_ratelimited("Event logged [IO_PAGE_FAULT device=%04x:%02x:%02x.%x domain=0x%04x address=0x%llx flags=0x%04x]\n", 515 + iommu->pci_seg->id, PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid), 581 516 domain_id, address, flags); 582 517 } 583 518 ··· 614 549 } 615 550 616 551 if (type == EVENT_TYPE_IO_FAULT) { 617 - amd_iommu_report_page_fault(devid, pasid, address, flags); 552 + amd_iommu_report_page_fault(iommu, devid, pasid, address, flags); 618 553 return; 619 554 } 620 555 621 556 switch (type) { 622 557 case EVENT_TYPE_ILL_DEV: 623 - dev_err(dev, "Event logged [ILLEGAL_DEV_TABLE_ENTRY device=%02x:%02x.%x pasid=0x%05x address=0x%llx flags=0x%04x]\n", 624 - PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid), 558 + dev_err(dev, "Event logged [ILLEGAL_DEV_TABLE_ENTRY device=%04x:%02x:%02x.%x pasid=0x%05x address=0x%llx flags=0x%04x]\n", 559 + iommu->pci_seg->id, PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid), 625 560 pasid, address, flags); 626 - dump_dte_entry(devid); 561 + dump_dte_entry(iommu, devid); 627 562 break; 628 563 case EVENT_TYPE_DEV_TAB_ERR: 629 - dev_err(dev, "Event logged [DEV_TAB_HARDWARE_ERROR device=%02x:%02x.%x " 564 + dev_err(dev, "Event logged [DEV_TAB_HARDWARE_ERROR device=%04x:%02x:%02x.%x " 630 565 "address=0x%llx flags=0x%04x]\n", 631 - PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid), 566 + iommu->pci_seg->id, PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid), 632 567 address, flags); 633 568 break; 634 569 case EVENT_TYPE_PAGE_TAB_ERR: 635 - dev_err(dev, "Event logged [PAGE_TAB_HARDWARE_ERROR device=%02x:%02x.%x pasid=0x%04x address=0x%llx flags=0x%04x]\n", 636 - PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid), 570 + dev_err(dev, "Event logged [PAGE_TAB_HARDWARE_ERROR device=%04x:%02x:%02x.%x pasid=0x%04x address=0x%llx flags=0x%04x]\n", 571 + iommu->pci_seg->id, PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid), 637 572 pasid, address, flags); 638 573 break; 639 574 case EVENT_TYPE_ILL_CMD: ··· 645 580 address, flags); 646 581 break; 647 582 case EVENT_TYPE_IOTLB_INV_TO: 648 - dev_err(dev, "Event logged [IOTLB_INV_TIMEOUT device=%02x:%02x.%x address=0x%llx]\n", 649 - PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid), 583 + dev_err(dev, "Event logged [IOTLB_INV_TIMEOUT device=%04x:%02x:%02x.%x address=0x%llx]\n", 584 + iommu->pci_seg->id, PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid), 650 585 address); 651 586 break; 652 587 case EVENT_TYPE_INV_DEV_REQ: 653 - dev_err(dev, "Event logged [INVALID_DEVICE_REQUEST device=%02x:%02x.%x pasid=0x%05x address=0x%llx flags=0x%04x]\n", 654 - PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid), 588 + dev_err(dev, "Event logged [INVALID_DEVICE_REQUEST device=%04x:%02x:%02x.%x pasid=0x%05x address=0x%llx flags=0x%04x]\n", 589 + iommu->pci_seg->id, PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid), 655 590 pasid, address, flags); 656 591 break; 657 592 case EVENT_TYPE_RMP_FAULT: 658 - amd_iommu_report_rmp_fault(event); 593 + amd_iommu_report_rmp_fault(iommu, event); 659 594 break; 660 595 case EVENT_TYPE_RMP_HW_ERR: 661 - amd_iommu_report_rmp_hw_error(event); 596 + amd_iommu_report_rmp_hw_error(iommu, event); 662 597 break; 663 598 case EVENT_TYPE_INV_PPR_REQ: 664 599 pasid = PPR_PASID(*((u64 *)__evt)); 665 600 tag = event[1] & 0x03FF; 666 - dev_err(dev, "Event logged [INVALID_PPR_REQUEST device=%02x:%02x.%x pasid=0x%05x address=0x%llx flags=0x%04x tag=0x%03x]\n", 667 - PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid), 601 + dev_err(dev, "Event logged [INVALID_PPR_REQUEST device=%04x:%02x:%02x.%x pasid=0x%05x address=0x%llx flags=0x%04x tag=0x%03x]\n", 602 + iommu->pci_seg->id, PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid), 668 603 pasid, address, flags, tag); 669 604 break; 670 605 default: ··· 701 636 702 637 fault.address = raw[1]; 703 638 fault.pasid = PPR_PASID(raw[0]); 704 - fault.device_id = PPR_DEVID(raw[0]); 639 + fault.sbdf = PCI_SEG_DEVID_TO_SBDF(iommu->pci_seg->id, PPR_DEVID(raw[0])); 705 640 fault.tag = PPR_TAG(raw[0]); 706 641 fault.flags = PPR_FLAGS(raw[0]); 707 642 ··· 1190 1125 static void amd_iommu_flush_dte_all(struct amd_iommu *iommu) 1191 1126 { 1192 1127 u32 devid; 1128 + u16 last_bdf = iommu->pci_seg->last_bdf; 1193 1129 1194 - for (devid = 0; devid <= 0xffff; ++devid) 1130 + for (devid = 0; devid <= last_bdf; ++devid) 1195 1131 iommu_flush_dte(iommu, devid); 1196 1132 1197 1133 iommu_completion_wait(iommu); ··· 1205 1139 static void amd_iommu_flush_tlb_all(struct amd_iommu *iommu) 1206 1140 { 1207 1141 u32 dom_id; 1142 + u16 last_bdf = iommu->pci_seg->last_bdf; 1208 1143 1209 - for (dom_id = 0; dom_id <= 0xffff; ++dom_id) { 1144 + for (dom_id = 0; dom_id <= last_bdf; ++dom_id) { 1210 1145 struct iommu_cmd cmd; 1211 1146 build_inv_iommu_pages(&cmd, 0, CMD_INV_IOMMU_ALL_PAGES_ADDRESS, 1212 1147 dom_id, 1); ··· 1250 1183 static void amd_iommu_flush_irt_all(struct amd_iommu *iommu) 1251 1184 { 1252 1185 u32 devid; 1186 + u16 last_bdf = iommu->pci_seg->last_bdf; 1253 1187 1254 - for (devid = 0; devid <= MAX_DEV_TABLE_ENTRIES; devid++) 1188 + for (devid = 0; devid <= last_bdf; devid++) 1255 1189 iommu_flush_irt(iommu, devid); 1256 1190 1257 1191 iommu_completion_wait(iommu); ··· 1280 1212 int qdep; 1281 1213 1282 1214 qdep = dev_data->ats.qdep; 1283 - iommu = amd_iommu_rlookup_table[dev_data->devid]; 1215 + iommu = rlookup_amd_iommu(dev_data->dev); 1216 + if (!iommu) 1217 + return -EINVAL; 1284 1218 1285 1219 build_inv_iotlb_pages(&cmd, dev_data->devid, qdep, address, size); 1286 1220 ··· 1302 1232 static int device_flush_dte(struct iommu_dev_data *dev_data) 1303 1233 { 1304 1234 struct amd_iommu *iommu; 1235 + struct pci_dev *pdev = NULL; 1236 + struct amd_iommu_pci_seg *pci_seg; 1305 1237 u16 alias; 1306 1238 int ret; 1307 1239 1308 - iommu = amd_iommu_rlookup_table[dev_data->devid]; 1240 + iommu = rlookup_amd_iommu(dev_data->dev); 1241 + if (!iommu) 1242 + return -EINVAL; 1309 1243 1310 - if (dev_data->pdev) 1311 - ret = pci_for_each_dma_alias(dev_data->pdev, 1244 + if (dev_is_pci(dev_data->dev)) 1245 + pdev = to_pci_dev(dev_data->dev); 1246 + 1247 + if (pdev) 1248 + ret = pci_for_each_dma_alias(pdev, 1312 1249 device_flush_dte_alias, iommu); 1313 1250 else 1314 1251 ret = iommu_flush_dte(iommu, dev_data->devid); 1315 1252 if (ret) 1316 1253 return ret; 1317 1254 1318 - alias = amd_iommu_alias_table[dev_data->devid]; 1255 + pci_seg = iommu->pci_seg; 1256 + alias = pci_seg->alias_table[dev_data->devid]; 1319 1257 if (alias != dev_data->devid) { 1320 1258 ret = iommu_flush_dte(iommu, alias); 1321 1259 if (ret) ··· 1539 1461 free_page((unsigned long)domain->gcr3_tbl); 1540 1462 } 1541 1463 1542 - static void set_dte_entry(u16 devid, struct protection_domain *domain, 1543 - bool ats, bool ppr) 1464 + static void set_dte_entry(struct amd_iommu *iommu, u16 devid, 1465 + struct protection_domain *domain, bool ats, bool ppr) 1544 1466 { 1545 1467 u64 pte_root = 0; 1546 1468 u64 flags = 0; 1547 1469 u32 old_domid; 1470 + struct dev_table_entry *dev_table = get_dev_table(iommu); 1548 1471 1549 1472 if (domain->iop.mode != PAGE_MODE_NONE) 1550 1473 pte_root = iommu_virt_to_phys(domain->iop.root); 1551 1474 1552 1475 pte_root |= (domain->iop.mode & DEV_ENTRY_MODE_MASK) 1553 1476 << DEV_ENTRY_MODE_SHIFT; 1554 - pte_root |= DTE_FLAG_IR | DTE_FLAG_IW | DTE_FLAG_V | DTE_FLAG_TV; 1555 1477 1556 - flags = amd_iommu_dev_table[devid].data[1]; 1478 + pte_root |= DTE_FLAG_IR | DTE_FLAG_IW | DTE_FLAG_V; 1479 + 1480 + /* 1481 + * When SNP is enabled, Only set TV bit when IOMMU 1482 + * page translation is in use. 1483 + */ 1484 + if (!amd_iommu_snp_en || (domain->id != 0)) 1485 + pte_root |= DTE_FLAG_TV; 1486 + 1487 + flags = dev_table[devid].data[1]; 1557 1488 1558 1489 if (ats) 1559 1490 flags |= DTE_FLAG_IOTLB; 1560 1491 1561 1492 if (ppr) { 1562 - struct amd_iommu *iommu = amd_iommu_rlookup_table[devid]; 1563 - 1564 1493 if (iommu_feature(iommu, FEATURE_EPHSUP)) 1565 1494 pte_root |= 1ULL << DEV_ENTRY_PPR; 1566 1495 } ··· 1601 1516 flags &= ~DEV_DOMID_MASK; 1602 1517 flags |= domain->id; 1603 1518 1604 - old_domid = amd_iommu_dev_table[devid].data[1] & DEV_DOMID_MASK; 1605 - amd_iommu_dev_table[devid].data[1] = flags; 1606 - amd_iommu_dev_table[devid].data[0] = pte_root; 1519 + old_domid = dev_table[devid].data[1] & DEV_DOMID_MASK; 1520 + dev_table[devid].data[1] = flags; 1521 + dev_table[devid].data[0] = pte_root; 1607 1522 1608 1523 /* 1609 1524 * A kdump kernel might be replacing a domain ID that was copied from ··· 1611 1526 * entries for the old domain ID that is being overwritten 1612 1527 */ 1613 1528 if (old_domid) { 1614 - struct amd_iommu *iommu = amd_iommu_rlookup_table[devid]; 1615 - 1616 1529 amd_iommu_flush_tlb_domid(iommu, old_domid); 1617 1530 } 1618 1531 } 1619 1532 1620 - static void clear_dte_entry(u16 devid) 1533 + static void clear_dte_entry(struct amd_iommu *iommu, u16 devid) 1621 1534 { 1622 - /* remove entry from the device table seen by the hardware */ 1623 - amd_iommu_dev_table[devid].data[0] = DTE_FLAG_V | DTE_FLAG_TV; 1624 - amd_iommu_dev_table[devid].data[1] &= DTE_FLAG_MASK; 1535 + struct dev_table_entry *dev_table = get_dev_table(iommu); 1625 1536 1626 - amd_iommu_apply_erratum_63(devid); 1537 + /* remove entry from the device table seen by the hardware */ 1538 + dev_table[devid].data[0] = DTE_FLAG_V; 1539 + 1540 + if (!amd_iommu_snp_en) 1541 + dev_table[devid].data[0] |= DTE_FLAG_TV; 1542 + 1543 + dev_table[devid].data[1] &= DTE_FLAG_MASK; 1544 + 1545 + amd_iommu_apply_erratum_63(iommu, devid); 1627 1546 } 1628 1547 1629 1548 static void do_attach(struct iommu_dev_data *dev_data, ··· 1636 1547 struct amd_iommu *iommu; 1637 1548 bool ats; 1638 1549 1639 - iommu = amd_iommu_rlookup_table[dev_data->devid]; 1550 + iommu = rlookup_amd_iommu(dev_data->dev); 1551 + if (!iommu) 1552 + return; 1640 1553 ats = dev_data->ats.enabled; 1641 1554 1642 1555 /* Update data structures */ ··· 1650 1559 domain->dev_cnt += 1; 1651 1560 1652 1561 /* Update device table */ 1653 - set_dte_entry(dev_data->devid, domain, 1562 + set_dte_entry(iommu, dev_data->devid, domain, 1654 1563 ats, dev_data->iommu_v2); 1655 - clone_aliases(dev_data->pdev); 1564 + clone_aliases(iommu, dev_data->dev); 1656 1565 1657 1566 device_flush_dte(dev_data); 1658 1567 } ··· 1662 1571 struct protection_domain *domain = dev_data->domain; 1663 1572 struct amd_iommu *iommu; 1664 1573 1665 - iommu = amd_iommu_rlookup_table[dev_data->devid]; 1574 + iommu = rlookup_amd_iommu(dev_data->dev); 1575 + if (!iommu) 1576 + return; 1666 1577 1667 1578 /* Update data structures */ 1668 1579 dev_data->domain = NULL; 1669 1580 list_del(&dev_data->list); 1670 - clear_dte_entry(dev_data->devid); 1671 - clone_aliases(dev_data->pdev); 1581 + clear_dte_entry(iommu, dev_data->devid); 1582 + clone_aliases(iommu, dev_data->dev); 1672 1583 1673 1584 /* Flush the DTE entry */ 1674 1585 device_flush_dte(dev_data); ··· 1842 1749 { 1843 1750 struct iommu_device *iommu_dev; 1844 1751 struct amd_iommu *iommu; 1845 - int ret, devid; 1752 + int ret; 1846 1753 1847 1754 if (!check_device(dev)) 1848 1755 return ERR_PTR(-ENODEV); 1849 1756 1850 - devid = get_device_id(dev); 1851 - iommu = amd_iommu_rlookup_table[devid]; 1757 + iommu = rlookup_amd_iommu(dev); 1758 + if (!iommu) 1759 + return ERR_PTR(-ENODEV); 1852 1760 1853 1761 if (dev_iommu_priv_get(dev)) 1854 1762 return &iommu->iommu; 1855 1763 1856 - ret = iommu_init_device(dev); 1764 + ret = iommu_init_device(iommu, dev); 1857 1765 if (ret) { 1858 1766 if (ret != -ENOTSUPP) 1859 1767 dev_err(dev, "Failed to initialize - trying to proceed anyway\n"); 1860 1768 iommu_dev = ERR_PTR(ret); 1861 - iommu_ignore_device(dev); 1769 + iommu_ignore_device(iommu, dev); 1862 1770 } else { 1863 1771 amd_iommu_set_pci_msi_domain(dev, iommu); 1864 1772 iommu_dev = &iommu->iommu; ··· 1879 1785 1880 1786 static void amd_iommu_release_device(struct device *dev) 1881 1787 { 1882 - int devid = get_device_id(dev); 1883 1788 struct amd_iommu *iommu; 1884 1789 1885 1790 if (!check_device(dev)) 1886 1791 return; 1887 1792 1888 - iommu = amd_iommu_rlookup_table[devid]; 1793 + iommu = rlookup_amd_iommu(dev); 1794 + if (!iommu) 1795 + return; 1889 1796 1890 1797 amd_iommu_uninit_device(dev); 1891 1798 iommu_completion_wait(iommu); ··· 1911 1816 struct iommu_dev_data *dev_data; 1912 1817 1913 1818 list_for_each_entry(dev_data, &domain->dev_list, list) { 1914 - set_dte_entry(dev_data->devid, domain, 1819 + struct amd_iommu *iommu = rlookup_amd_iommu(dev_data->dev); 1820 + 1821 + if (!iommu) 1822 + continue; 1823 + set_dte_entry(iommu, dev_data->devid, domain, 1915 1824 dev_data->ats.enabled, dev_data->iommu_v2); 1916 - clone_aliases(dev_data->pdev); 1825 + clone_aliases(iommu, dev_data->dev); 1917 1826 } 1918 1827 } 1919 1828 ··· 2068 1969 { 2069 1970 struct protection_domain *domain; 2070 1971 1972 + /* 1973 + * Since DTE[Mode]=0 is prohibited on SNP-enabled system, 1974 + * default to use IOMMU_DOMAIN_DMA[_FQ]. 1975 + */ 1976 + if (amd_iommu_snp_en && (type == IOMMU_DOMAIN_IDENTITY)) 1977 + return NULL; 1978 + 2071 1979 domain = protection_domain_alloc(type); 2072 1980 if (!domain) 2073 1981 return NULL; ··· 2110 2004 struct device *dev) 2111 2005 { 2112 2006 struct iommu_dev_data *dev_data = dev_iommu_priv_get(dev); 2113 - int devid = get_device_id(dev); 2114 2007 struct amd_iommu *iommu; 2115 2008 2116 2009 if (!check_device(dev)) ··· 2118 2013 if (dev_data->domain != NULL) 2119 2014 detach_device(dev); 2120 2015 2121 - iommu = amd_iommu_rlookup_table[devid]; 2016 + iommu = rlookup_amd_iommu(dev); 2122 2017 if (!iommu) 2123 2018 return; 2124 2019 ··· 2145 2040 dev_data = dev_iommu_priv_get(dev); 2146 2041 dev_data->defer_attach = false; 2147 2042 2148 - iommu = amd_iommu_rlookup_table[dev_data->devid]; 2043 + iommu = rlookup_amd_iommu(dev); 2149 2044 if (!iommu) 2150 2045 return -EINVAL; 2151 2046 ··· 2274 2169 { 2275 2170 struct iommu_resv_region *region; 2276 2171 struct unity_map_entry *entry; 2277 - int devid; 2172 + struct amd_iommu *iommu; 2173 + struct amd_iommu_pci_seg *pci_seg; 2174 + int devid, sbdf; 2278 2175 2279 - devid = get_device_id(dev); 2280 - if (devid < 0) 2176 + sbdf = get_device_sbdf_id(dev); 2177 + if (sbdf < 0) 2281 2178 return; 2282 2179 2283 - list_for_each_entry(entry, &amd_iommu_unity_map, list) { 2180 + devid = PCI_SBDF_TO_DEVID(sbdf); 2181 + iommu = rlookup_amd_iommu(dev); 2182 + if (!iommu) 2183 + return; 2184 + pci_seg = iommu->pci_seg; 2185 + 2186 + list_for_each_entry(entry, &pci_seg->unity_map, list) { 2284 2187 int type, prot = 0; 2285 2188 size_t length; 2286 2189 ··· 2393 2280 .probe_finalize = amd_iommu_probe_finalize, 2394 2281 .device_group = amd_iommu_device_group, 2395 2282 .get_resv_regions = amd_iommu_get_resv_regions, 2396 - .put_resv_regions = generic_iommu_put_resv_regions, 2397 2283 .is_attach_deferred = amd_iommu_is_attach_deferred, 2398 2284 .pgsize_bitmap = AMD_IOMMU_PGSIZES, 2399 2285 .def_domain_type = amd_iommu_def_domain_type, ··· 2531 2419 continue; 2532 2420 2533 2421 qdep = dev_data->ats.qdep; 2534 - iommu = amd_iommu_rlookup_table[dev_data->devid]; 2535 - 2422 + iommu = rlookup_amd_iommu(dev_data->dev); 2423 + if (!iommu) 2424 + continue; 2536 2425 build_inv_iotlb_pasid(&cmd, dev_data->devid, pasid, 2537 2426 qdep, address, size); 2538 2427 ··· 2695 2582 struct iommu_cmd cmd; 2696 2583 2697 2584 dev_data = dev_iommu_priv_get(&pdev->dev); 2698 - iommu = amd_iommu_rlookup_table[dev_data->devid]; 2585 + iommu = rlookup_amd_iommu(&pdev->dev); 2586 + if (!iommu) 2587 + return -ENODEV; 2699 2588 2700 2589 build_complete_ppr(&cmd, dev_data->devid, pasid, status, 2701 2590 tag, dev_data->pri_tlp); ··· 2759 2644 static struct irq_chip amd_ir_chip; 2760 2645 static DEFINE_SPINLOCK(iommu_table_lock); 2761 2646 2762 - static void set_dte_irq_entry(u16 devid, struct irq_remap_table *table) 2647 + static void set_dte_irq_entry(struct amd_iommu *iommu, u16 devid, 2648 + struct irq_remap_table *table) 2763 2649 { 2764 2650 u64 dte; 2651 + struct dev_table_entry *dev_table = get_dev_table(iommu); 2765 2652 2766 - dte = amd_iommu_dev_table[devid].data[2]; 2653 + dte = dev_table[devid].data[2]; 2767 2654 dte &= ~DTE_IRQ_PHYS_ADDR_MASK; 2768 2655 dte |= iommu_virt_to_phys(table->table); 2769 2656 dte |= DTE_IRQ_REMAP_INTCTL; 2770 2657 dte |= DTE_INTTABLEN; 2771 2658 dte |= DTE_IRQ_REMAP_ENABLE; 2772 2659 2773 - amd_iommu_dev_table[devid].data[2] = dte; 2660 + dev_table[devid].data[2] = dte; 2774 2661 } 2775 2662 2776 - static struct irq_remap_table *get_irq_table(u16 devid) 2663 + static struct irq_remap_table *get_irq_table(struct amd_iommu *iommu, u16 devid) 2777 2664 { 2778 2665 struct irq_remap_table *table; 2666 + struct amd_iommu_pci_seg *pci_seg = iommu->pci_seg; 2779 2667 2780 - if (WARN_ONCE(!amd_iommu_rlookup_table[devid], 2781 - "%s: no iommu for devid %x\n", __func__, devid)) 2668 + if (WARN_ONCE(!pci_seg->rlookup_table[devid], 2669 + "%s: no iommu for devid %x:%x\n", 2670 + __func__, pci_seg->id, devid)) 2782 2671 return NULL; 2783 2672 2784 - table = irq_lookup_table[devid]; 2785 - if (WARN_ONCE(!table, "%s: no table for devid %x\n", __func__, devid)) 2673 + table = pci_seg->irq_lookup_table[devid]; 2674 + if (WARN_ONCE(!table, "%s: no table for devid %x:%x\n", 2675 + __func__, pci_seg->id, devid)) 2786 2676 return NULL; 2787 2677 2788 2678 return table; ··· 2820 2700 static void set_remap_table_entry(struct amd_iommu *iommu, u16 devid, 2821 2701 struct irq_remap_table *table) 2822 2702 { 2823 - irq_lookup_table[devid] = table; 2824 - set_dte_irq_entry(devid, table); 2703 + struct amd_iommu_pci_seg *pci_seg = iommu->pci_seg; 2704 + 2705 + pci_seg->irq_lookup_table[devid] = table; 2706 + set_dte_irq_entry(iommu, devid, table); 2825 2707 iommu_flush_dte(iommu, devid); 2826 2708 } 2827 2709 ··· 2831 2709 void *data) 2832 2710 { 2833 2711 struct irq_remap_table *table = data; 2712 + struct amd_iommu_pci_seg *pci_seg; 2713 + struct amd_iommu *iommu = rlookup_amd_iommu(&pdev->dev); 2834 2714 2835 - irq_lookup_table[alias] = table; 2836 - set_dte_irq_entry(alias, table); 2715 + if (!iommu) 2716 + return -EINVAL; 2837 2717 2838 - iommu_flush_dte(amd_iommu_rlookup_table[alias], alias); 2718 + pci_seg = iommu->pci_seg; 2719 + pci_seg->irq_lookup_table[alias] = table; 2720 + set_dte_irq_entry(iommu, alias, table); 2721 + iommu_flush_dte(pci_seg->rlookup_table[alias], alias); 2839 2722 2840 2723 return 0; 2841 2724 } 2842 2725 2843 - static struct irq_remap_table *alloc_irq_table(u16 devid, struct pci_dev *pdev) 2726 + static struct irq_remap_table *alloc_irq_table(struct amd_iommu *iommu, 2727 + u16 devid, struct pci_dev *pdev) 2844 2728 { 2845 2729 struct irq_remap_table *table = NULL; 2846 2730 struct irq_remap_table *new_table = NULL; 2847 - struct amd_iommu *iommu; 2731 + struct amd_iommu_pci_seg *pci_seg; 2848 2732 unsigned long flags; 2849 2733 u16 alias; 2850 2734 2851 2735 spin_lock_irqsave(&iommu_table_lock, flags); 2852 2736 2853 - iommu = amd_iommu_rlookup_table[devid]; 2854 - if (!iommu) 2855 - goto out_unlock; 2856 - 2857 - table = irq_lookup_table[devid]; 2737 + pci_seg = iommu->pci_seg; 2738 + table = pci_seg->irq_lookup_table[devid]; 2858 2739 if (table) 2859 2740 goto out_unlock; 2860 2741 2861 - alias = amd_iommu_alias_table[devid]; 2862 - table = irq_lookup_table[alias]; 2742 + alias = pci_seg->alias_table[devid]; 2743 + table = pci_seg->irq_lookup_table[alias]; 2863 2744 if (table) { 2864 2745 set_remap_table_entry(iommu, devid, table); 2865 2746 goto out_wait; ··· 2876 2751 2877 2752 spin_lock_irqsave(&iommu_table_lock, flags); 2878 2753 2879 - table = irq_lookup_table[devid]; 2754 + table = pci_seg->irq_lookup_table[devid]; 2880 2755 if (table) 2881 2756 goto out_unlock; 2882 2757 2883 - table = irq_lookup_table[alias]; 2758 + table = pci_seg->irq_lookup_table[alias]; 2884 2759 if (table) { 2885 2760 set_remap_table_entry(iommu, devid, table); 2886 2761 goto out_wait; ··· 2911 2786 return table; 2912 2787 } 2913 2788 2914 - static int alloc_irq_index(u16 devid, int count, bool align, 2915 - struct pci_dev *pdev) 2789 + static int alloc_irq_index(struct amd_iommu *iommu, u16 devid, int count, 2790 + bool align, struct pci_dev *pdev) 2916 2791 { 2917 2792 struct irq_remap_table *table; 2918 2793 int index, c, alignment = 1; 2919 2794 unsigned long flags; 2920 - struct amd_iommu *iommu = amd_iommu_rlookup_table[devid]; 2921 2795 2922 - if (!iommu) 2923 - return -ENODEV; 2924 - 2925 - table = alloc_irq_table(devid, pdev); 2796 + table = alloc_irq_table(iommu, devid, pdev); 2926 2797 if (!table) 2927 2798 return -ENODEV; 2928 2799 ··· 2957 2836 return index; 2958 2837 } 2959 2838 2960 - static int modify_irte_ga(u16 devid, int index, struct irte_ga *irte, 2961 - struct amd_ir_data *data) 2839 + static int modify_irte_ga(struct amd_iommu *iommu, u16 devid, int index, 2840 + struct irte_ga *irte, struct amd_ir_data *data) 2962 2841 { 2963 2842 bool ret; 2964 2843 struct irq_remap_table *table; 2965 - struct amd_iommu *iommu; 2966 2844 unsigned long flags; 2967 2845 struct irte_ga *entry; 2968 2846 2969 - iommu = amd_iommu_rlookup_table[devid]; 2970 - if (iommu == NULL) 2971 - return -EINVAL; 2972 - 2973 - table = get_irq_table(devid); 2847 + table = get_irq_table(iommu, devid); 2974 2848 if (!table) 2975 2849 return -ENOMEM; 2976 2850 ··· 2996 2880 return 0; 2997 2881 } 2998 2882 2999 - static int modify_irte(u16 devid, int index, union irte *irte) 2883 + static int modify_irte(struct amd_iommu *iommu, 2884 + u16 devid, int index, union irte *irte) 3000 2885 { 3001 2886 struct irq_remap_table *table; 3002 - struct amd_iommu *iommu; 3003 2887 unsigned long flags; 3004 2888 3005 - iommu = amd_iommu_rlookup_table[devid]; 3006 - if (iommu == NULL) 3007 - return -EINVAL; 3008 - 3009 - table = get_irq_table(devid); 2889 + table = get_irq_table(iommu, devid); 3010 2890 if (!table) 3011 2891 return -ENOMEM; 3012 2892 ··· 3016 2904 return 0; 3017 2905 } 3018 2906 3019 - static void free_irte(u16 devid, int index) 2907 + static void free_irte(struct amd_iommu *iommu, u16 devid, int index) 3020 2908 { 3021 2909 struct irq_remap_table *table; 3022 - struct amd_iommu *iommu; 3023 2910 unsigned long flags; 3024 2911 3025 - iommu = amd_iommu_rlookup_table[devid]; 3026 - if (iommu == NULL) 3027 - return; 3028 - 3029 - table = get_irq_table(devid); 2912 + table = get_irq_table(iommu, devid); 3030 2913 if (!table) 3031 2914 return; 3032 2915 ··· 3063 2956 irte->lo.fields_remap.valid = 1; 3064 2957 } 3065 2958 3066 - static void irte_activate(void *entry, u16 devid, u16 index) 2959 + static void irte_activate(struct amd_iommu *iommu, void *entry, u16 devid, u16 index) 3067 2960 { 3068 2961 union irte *irte = (union irte *) entry; 3069 2962 3070 2963 irte->fields.valid = 1; 3071 - modify_irte(devid, index, irte); 2964 + modify_irte(iommu, devid, index, irte); 3072 2965 } 3073 2966 3074 - static void irte_ga_activate(void *entry, u16 devid, u16 index) 2967 + static void irte_ga_activate(struct amd_iommu *iommu, void *entry, u16 devid, u16 index) 3075 2968 { 3076 2969 struct irte_ga *irte = (struct irte_ga *) entry; 3077 2970 3078 2971 irte->lo.fields_remap.valid = 1; 3079 - modify_irte_ga(devid, index, irte, NULL); 2972 + modify_irte_ga(iommu, devid, index, irte, NULL); 3080 2973 } 3081 2974 3082 - static void irte_deactivate(void *entry, u16 devid, u16 index) 2975 + static void irte_deactivate(struct amd_iommu *iommu, void *entry, u16 devid, u16 index) 3083 2976 { 3084 2977 union irte *irte = (union irte *) entry; 3085 2978 3086 2979 irte->fields.valid = 0; 3087 - modify_irte(devid, index, irte); 2980 + modify_irte(iommu, devid, index, irte); 3088 2981 } 3089 2982 3090 - static void irte_ga_deactivate(void *entry, u16 devid, u16 index) 2983 + static void irte_ga_deactivate(struct amd_iommu *iommu, void *entry, u16 devid, u16 index) 3091 2984 { 3092 2985 struct irte_ga *irte = (struct irte_ga *) entry; 3093 2986 3094 2987 irte->lo.fields_remap.valid = 0; 3095 - modify_irte_ga(devid, index, irte, NULL); 2988 + modify_irte_ga(iommu, devid, index, irte, NULL); 3096 2989 } 3097 2990 3098 - static void irte_set_affinity(void *entry, u16 devid, u16 index, 2991 + static void irte_set_affinity(struct amd_iommu *iommu, void *entry, u16 devid, u16 index, 3099 2992 u8 vector, u32 dest_apicid) 3100 2993 { 3101 2994 union irte *irte = (union irte *) entry; 3102 2995 3103 2996 irte->fields.vector = vector; 3104 2997 irte->fields.destination = dest_apicid; 3105 - modify_irte(devid, index, irte); 2998 + modify_irte(iommu, devid, index, irte); 3106 2999 } 3107 3000 3108 - static void irte_ga_set_affinity(void *entry, u16 devid, u16 index, 3001 + static void irte_ga_set_affinity(struct amd_iommu *iommu, void *entry, u16 devid, u16 index, 3109 3002 u8 vector, u32 dest_apicid) 3110 3003 { 3111 3004 struct irte_ga *irte = (struct irte_ga *) entry; ··· 3116 3009 APICID_TO_IRTE_DEST_LO(dest_apicid); 3117 3010 irte->hi.fields.destination = 3118 3011 APICID_TO_IRTE_DEST_HI(dest_apicid); 3119 - modify_irte_ga(devid, index, irte, NULL); 3012 + modify_irte_ga(iommu, devid, index, irte, NULL); 3120 3013 } 3121 3014 } 3122 3015 ··· 3175 3068 return get_hpet_devid(info->devid); 3176 3069 case X86_IRQ_ALLOC_TYPE_PCI_MSI: 3177 3070 case X86_IRQ_ALLOC_TYPE_PCI_MSIX: 3178 - return get_device_id(msi_desc_to_dev(info->desc)); 3071 + return get_device_sbdf_id(msi_desc_to_dev(info->desc)); 3179 3072 default: 3180 3073 WARN_ON_ONCE(1); 3181 3074 return -1; ··· 3204 3097 int devid, int index, int sub_handle) 3205 3098 { 3206 3099 struct irq_2_irte *irte_info = &data->irq_2_irte; 3207 - struct amd_iommu *iommu = amd_iommu_rlookup_table[devid]; 3100 + struct amd_iommu *iommu = data->iommu; 3208 3101 3209 3102 if (!iommu) 3210 3103 return; ··· 3255 3148 struct irq_alloc_info *info = arg; 3256 3149 struct irq_data *irq_data; 3257 3150 struct amd_ir_data *data = NULL; 3151 + struct amd_iommu *iommu; 3258 3152 struct irq_cfg *cfg; 3259 - int i, ret, devid; 3153 + int i, ret, devid, seg, sbdf; 3260 3154 int index; 3261 3155 3262 3156 if (!info) ··· 3273 3165 if (info->type == X86_IRQ_ALLOC_TYPE_PCI_MSI) 3274 3166 info->flags &= ~X86_IRQ_ALLOC_CONTIGUOUS_VECTORS; 3275 3167 3276 - devid = get_devid(info); 3277 - if (devid < 0) 3168 + sbdf = get_devid(info); 3169 + if (sbdf < 0) 3170 + return -EINVAL; 3171 + 3172 + seg = PCI_SBDF_TO_SEGID(sbdf); 3173 + devid = PCI_SBDF_TO_DEVID(sbdf); 3174 + iommu = __rlookup_amd_iommu(seg, devid); 3175 + if (!iommu) 3278 3176 return -EINVAL; 3279 3177 3280 3178 ret = irq_domain_alloc_irqs_parent(domain, virq, nr_irqs, arg); ··· 3289 3175 3290 3176 if (info->type == X86_IRQ_ALLOC_TYPE_IOAPIC) { 3291 3177 struct irq_remap_table *table; 3292 - struct amd_iommu *iommu; 3293 3178 3294 - table = alloc_irq_table(devid, NULL); 3179 + table = alloc_irq_table(iommu, devid, NULL); 3295 3180 if (table) { 3296 3181 if (!table->min_index) { 3297 3182 /* ··· 3298 3185 * interrupts. 3299 3186 */ 3300 3187 table->min_index = 32; 3301 - iommu = amd_iommu_rlookup_table[devid]; 3302 3188 for (i = 0; i < 32; ++i) 3303 3189 iommu->irte_ops->set_allocated(table, i); 3304 3190 } ··· 3310 3198 info->type == X86_IRQ_ALLOC_TYPE_PCI_MSIX) { 3311 3199 bool align = (info->type == X86_IRQ_ALLOC_TYPE_PCI_MSI); 3312 3200 3313 - index = alloc_irq_index(devid, nr_irqs, align, 3201 + index = alloc_irq_index(iommu, devid, nr_irqs, align, 3314 3202 msi_desc_to_pci_dev(info->desc)); 3315 3203 } else { 3316 - index = alloc_irq_index(devid, nr_irqs, false, NULL); 3204 + index = alloc_irq_index(iommu, devid, nr_irqs, false, NULL); 3317 3205 } 3318 3206 3319 3207 if (index < 0) { ··· 3345 3233 goto out_free_data; 3346 3234 } 3347 3235 3236 + data->iommu = iommu; 3348 3237 irq_data->hwirq = (devid << 16) + i; 3349 3238 irq_data->chip_data = data; 3350 3239 irq_data->chip = &amd_ir_chip; ··· 3362 3249 kfree(irq_data->chip_data); 3363 3250 } 3364 3251 for (i = 0; i < nr_irqs; i++) 3365 - free_irte(devid, index + i); 3252 + free_irte(iommu, devid, index + i); 3366 3253 out_free_parent: 3367 3254 irq_domain_free_irqs_common(domain, virq, nr_irqs); 3368 3255 return ret; ··· 3381 3268 if (irq_data && irq_data->chip_data) { 3382 3269 data = irq_data->chip_data; 3383 3270 irte_info = &data->irq_2_irte; 3384 - free_irte(irte_info->devid, irte_info->index); 3271 + free_irte(data->iommu, irte_info->devid, irte_info->index); 3385 3272 kfree(data->entry); 3386 3273 kfree(data); 3387 3274 } ··· 3399 3286 { 3400 3287 struct amd_ir_data *data = irq_data->chip_data; 3401 3288 struct irq_2_irte *irte_info = &data->irq_2_irte; 3402 - struct amd_iommu *iommu = amd_iommu_rlookup_table[irte_info->devid]; 3289 + struct amd_iommu *iommu = data->iommu; 3403 3290 struct irq_cfg *cfg = irqd_cfg(irq_data); 3404 3291 3405 3292 if (!iommu) 3406 3293 return 0; 3407 3294 3408 - iommu->irte_ops->activate(data->entry, irte_info->devid, 3295 + iommu->irte_ops->activate(iommu, data->entry, irte_info->devid, 3409 3296 irte_info->index); 3410 3297 amd_ir_update_irte(irq_data, iommu, data, irte_info, cfg); 3411 3298 return 0; ··· 3416 3303 { 3417 3304 struct amd_ir_data *data = irq_data->chip_data; 3418 3305 struct irq_2_irte *irte_info = &data->irq_2_irte; 3419 - struct amd_iommu *iommu = amd_iommu_rlookup_table[irte_info->devid]; 3306 + struct amd_iommu *iommu = data->iommu; 3420 3307 3421 3308 if (iommu) 3422 - iommu->irte_ops->deactivate(data->entry, irte_info->devid, 3309 + iommu->irte_ops->deactivate(iommu, data->entry, irte_info->devid, 3423 3310 irte_info->index); 3424 3311 } 3425 3312 ··· 3439 3326 3440 3327 if (devid < 0) 3441 3328 return 0; 3329 + iommu = __rlookup_amd_iommu((devid >> 16), (devid & 0xffff)); 3442 3330 3443 - iommu = amd_iommu_rlookup_table[devid]; 3444 3331 return iommu && iommu->ir_domain == d; 3445 3332 } 3446 3333 ··· 3474 3361 entry->hi.fields.vector = ir_data->ga_vector; 3475 3362 entry->lo.fields_vapic.ga_tag = ir_data->ga_tag; 3476 3363 3477 - return modify_irte_ga(ir_data->irq_2_irte.devid, 3364 + return modify_irte_ga(ir_data->iommu, ir_data->irq_2_irte.devid, 3478 3365 ir_data->irq_2_irte.index, entry, ir_data); 3479 3366 } 3480 3367 EXPORT_SYMBOL(amd_iommu_activate_guest_mode); ··· 3504 3391 entry->hi.fields.destination = 3505 3392 APICID_TO_IRTE_DEST_HI(cfg->dest_apicid); 3506 3393 3507 - return modify_irte_ga(ir_data->irq_2_irte.devid, 3394 + return modify_irte_ga(ir_data->iommu, ir_data->irq_2_irte.devid, 3508 3395 ir_data->irq_2_irte.index, entry, ir_data); 3509 3396 } 3510 3397 EXPORT_SYMBOL(amd_iommu_deactivate_guest_mode); ··· 3512 3399 static int amd_ir_set_vcpu_affinity(struct irq_data *data, void *vcpu_info) 3513 3400 { 3514 3401 int ret; 3515 - struct amd_iommu *iommu; 3516 3402 struct amd_iommu_pi_data *pi_data = vcpu_info; 3517 3403 struct vcpu_data *vcpu_pi_info = pi_data->vcpu_data; 3518 3404 struct amd_ir_data *ir_data = data->chip_data; 3519 3405 struct irq_2_irte *irte_info = &ir_data->irq_2_irte; 3520 - struct iommu_dev_data *dev_data = search_dev_data(irte_info->devid); 3406 + struct iommu_dev_data *dev_data; 3407 + 3408 + if (ir_data->iommu == NULL) 3409 + return -EINVAL; 3410 + 3411 + dev_data = search_dev_data(ir_data->iommu, irte_info->devid); 3521 3412 3522 3413 /* Note: 3523 3414 * This device has never been set up for guest mode. ··· 3542 3425 __func__); 3543 3426 pi_data->is_guest_mode = false; 3544 3427 } 3545 - 3546 - iommu = amd_iommu_rlookup_table[irte_info->devid]; 3547 - if (iommu == NULL) 3548 - return -EINVAL; 3549 3428 3550 3429 pi_data->prev_ga_tag = ir_data->cached_ga_tag; 3551 3430 if (pi_data->is_guest_mode) { ··· 3576 3463 * Atomically updates the IRTE with the new destination, vector 3577 3464 * and flushes the interrupt entry cache. 3578 3465 */ 3579 - iommu->irte_ops->set_affinity(ir_data->entry, irte_info->devid, 3466 + iommu->irte_ops->set_affinity(iommu, ir_data->entry, irte_info->devid, 3580 3467 irte_info->index, cfg->vector, 3581 3468 cfg->dest_apicid); 3582 3469 } ··· 3588 3475 struct irq_2_irte *irte_info = &ir_data->irq_2_irte; 3589 3476 struct irq_cfg *cfg = irqd_cfg(data); 3590 3477 struct irq_data *parent = data->parent_data; 3591 - struct amd_iommu *iommu = amd_iommu_rlookup_table[irte_info->devid]; 3478 + struct amd_iommu *iommu = ir_data->iommu; 3592 3479 int ret; 3593 3480 3594 3481 if (!iommu) ··· 3658 3545 !ref || !entry || !entry->lo.fields_vapic.guest_mode) 3659 3546 return 0; 3660 3547 3661 - iommu = amd_iommu_rlookup_table[devid]; 3548 + iommu = ir_data->iommu; 3662 3549 if (!iommu) 3663 3550 return -ENODEV; 3664 3551 3665 - table = get_irq_table(devid); 3552 + table = get_irq_table(iommu, devid); 3666 3553 if (!table) 3667 3554 return -ENODEV; 3668 3555
+29 -38
drivers/iommu/amd/iommu_v2.c
··· 51 51 52 52 struct device_state { 53 53 struct list_head list; 54 - u16 devid; 54 + u32 sbdf; 55 55 atomic_t count; 56 56 struct pci_dev *pdev; 57 57 struct pasid_state **states; ··· 83 83 84 84 static void free_pasid_states(struct device_state *dev_state); 85 85 86 - static u16 device_id(struct pci_dev *pdev) 87 - { 88 - u16 devid; 89 - 90 - devid = pdev->bus->number; 91 - devid = (devid << 8) | pdev->devfn; 92 - 93 - return devid; 94 - } 95 - 96 - static struct device_state *__get_device_state(u16 devid) 86 + static struct device_state *__get_device_state(u32 sbdf) 97 87 { 98 88 struct device_state *dev_state; 99 89 100 90 list_for_each_entry(dev_state, &state_list, list) { 101 - if (dev_state->devid == devid) 91 + if (dev_state->sbdf == sbdf) 102 92 return dev_state; 103 93 } 104 94 105 95 return NULL; 106 96 } 107 97 108 - static struct device_state *get_device_state(u16 devid) 98 + static struct device_state *get_device_state(u32 sbdf) 109 99 { 110 100 struct device_state *dev_state; 111 101 unsigned long flags; 112 102 113 103 spin_lock_irqsave(&state_lock, flags); 114 - dev_state = __get_device_state(devid); 104 + dev_state = __get_device_state(sbdf); 115 105 if (dev_state != NULL) 116 106 atomic_inc(&dev_state->count); 117 107 spin_unlock_irqrestore(&state_lock, flags); ··· 518 528 unsigned long flags; 519 529 struct fault *fault; 520 530 bool finish; 521 - u16 tag, devid; 531 + u16 tag, devid, seg_id; 522 532 int ret; 523 533 524 534 iommu_fault = data; 525 535 tag = iommu_fault->tag & 0x1ff; 526 536 finish = (iommu_fault->tag >> 9) & 1; 527 537 528 - devid = iommu_fault->device_id; 529 - pdev = pci_get_domain_bus_and_slot(0, PCI_BUS_NUM(devid), 538 + seg_id = PCI_SBDF_TO_SEGID(iommu_fault->sbdf); 539 + devid = PCI_SBDF_TO_DEVID(iommu_fault->sbdf); 540 + pdev = pci_get_domain_bus_and_slot(seg_id, PCI_BUS_NUM(devid), 530 541 devid & 0xff); 531 542 if (!pdev) 532 543 return -ENODEV; ··· 541 550 goto out; 542 551 } 543 552 544 - dev_state = get_device_state(iommu_fault->device_id); 553 + dev_state = get_device_state(iommu_fault->sbdf); 545 554 if (dev_state == NULL) 546 555 goto out; 547 556 ··· 600 609 struct pasid_state *pasid_state; 601 610 struct device_state *dev_state; 602 611 struct mm_struct *mm; 603 - u16 devid; 612 + u32 sbdf; 604 613 int ret; 605 614 606 615 might_sleep(); ··· 608 617 if (!amd_iommu_v2_supported()) 609 618 return -ENODEV; 610 619 611 - devid = device_id(pdev); 612 - dev_state = get_device_state(devid); 620 + sbdf = get_pci_sbdf_id(pdev); 621 + dev_state = get_device_state(sbdf); 613 622 614 623 if (dev_state == NULL) 615 624 return -EINVAL; ··· 683 692 { 684 693 struct pasid_state *pasid_state; 685 694 struct device_state *dev_state; 686 - u16 devid; 695 + u32 sbdf; 687 696 688 697 might_sleep(); 689 698 690 699 if (!amd_iommu_v2_supported()) 691 700 return; 692 701 693 - devid = device_id(pdev); 694 - dev_state = get_device_state(devid); 702 + sbdf = get_pci_sbdf_id(pdev); 703 + dev_state = get_device_state(sbdf); 695 704 if (dev_state == NULL) 696 705 return; 697 706 ··· 733 742 struct iommu_group *group; 734 743 unsigned long flags; 735 744 int ret, tmp; 736 - u16 devid; 745 + u32 sbdf; 737 746 738 747 might_sleep(); 739 748 ··· 750 759 if (pasids <= 0 || pasids > (PASID_MASK + 1)) 751 760 return -EINVAL; 752 761 753 - devid = device_id(pdev); 762 + sbdf = get_pci_sbdf_id(pdev); 754 763 755 764 dev_state = kzalloc(sizeof(*dev_state), GFP_KERNEL); 756 765 if (dev_state == NULL) ··· 759 768 spin_lock_init(&dev_state->lock); 760 769 init_waitqueue_head(&dev_state->wq); 761 770 dev_state->pdev = pdev; 762 - dev_state->devid = devid; 771 + dev_state->sbdf = sbdf; 763 772 764 773 tmp = pasids; 765 774 for (dev_state->pasid_levels = 0; (tmp - 1) & ~0x1ff; tmp >>= 9) ··· 797 806 798 807 spin_lock_irqsave(&state_lock, flags); 799 808 800 - if (__get_device_state(devid) != NULL) { 809 + if (__get_device_state(sbdf) != NULL) { 801 810 spin_unlock_irqrestore(&state_lock, flags); 802 811 ret = -EBUSY; 803 812 goto out_free_domain; ··· 829 838 { 830 839 struct device_state *dev_state; 831 840 unsigned long flags; 832 - u16 devid; 841 + u32 sbdf; 833 842 834 843 if (!amd_iommu_v2_supported()) 835 844 return; 836 845 837 - devid = device_id(pdev); 846 + sbdf = get_pci_sbdf_id(pdev); 838 847 839 848 spin_lock_irqsave(&state_lock, flags); 840 849 841 - dev_state = __get_device_state(devid); 850 + dev_state = __get_device_state(sbdf); 842 851 if (dev_state == NULL) { 843 852 spin_unlock_irqrestore(&state_lock, flags); 844 853 return; ··· 858 867 { 859 868 struct device_state *dev_state; 860 869 unsigned long flags; 861 - u16 devid; 870 + u32 sbdf; 862 871 int ret; 863 872 864 873 if (!amd_iommu_v2_supported()) 865 874 return -ENODEV; 866 875 867 - devid = device_id(pdev); 876 + sbdf = get_pci_sbdf_id(pdev); 868 877 869 878 spin_lock_irqsave(&state_lock, flags); 870 879 871 880 ret = -EINVAL; 872 - dev_state = __get_device_state(devid); 881 + dev_state = __get_device_state(sbdf); 873 882 if (dev_state == NULL) 874 883 goto out_unlock; 875 884 ··· 889 898 { 890 899 struct device_state *dev_state; 891 900 unsigned long flags; 892 - u16 devid; 901 + u32 sbdf; 893 902 int ret; 894 903 895 904 if (!amd_iommu_v2_supported()) 896 905 return -ENODEV; 897 906 898 - devid = device_id(pdev); 907 + sbdf = get_pci_sbdf_id(pdev); 899 908 900 909 spin_lock_irqsave(&state_lock, flags); 901 910 902 911 ret = -EINVAL; 903 - dev_state = __get_device_state(devid); 912 + dev_state = __get_device_state(sbdf); 904 913 if (dev_state == NULL) 905 914 goto out_unlock; 906 915
+2 -2
drivers/iommu/amd/quirks.c
··· 15 15 16 16 struct ivrs_quirk_entry { 17 17 u8 id; 18 - u16 devid; 18 + u32 devid; 19 19 }; 20 20 21 21 enum { ··· 49 49 const struct ivrs_quirk_entry *i; 50 50 51 51 for (i = d->driver_data; i->id != 0 && i->devid != 0; i++) 52 - add_special_device(IVHD_SPECIAL_IOAPIC, i->id, (u16 *)&i->devid, 0); 52 + add_special_device(IVHD_SPECIAL_IOAPIC, i->id, (u32 *)&i->devid, 0); 53 53 54 54 return 0; 55 55 }
-4
drivers/iommu/apple-dart.c
··· 564 564 { 565 565 struct apple_dart_master_cfg *cfg = dev_iommu_priv_get(dev); 566 566 567 - if (!cfg) 568 - return; 569 - 570 567 dev_iommu_priv_set(dev, NULL); 571 568 kfree(cfg); 572 569 } ··· 768 771 .of_xlate = apple_dart_of_xlate, 769 772 .def_domain_type = apple_dart_def_domain_type, 770 773 .get_resv_regions = apple_dart_get_resv_regions, 771 - .put_resv_regions = generic_iommu_put_resv_regions, 772 774 .pgsize_bitmap = -1UL, /* Restricted during dart probe */ 773 775 .owner = THIS_MODULE, 774 776 .default_domain_ops = &(const struct iommu_domain_ops) {
+76 -68
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
··· 1380 1380 arm_smmu_cmdq_issue_cmd(smmu, &prefetch_cmd); 1381 1381 } 1382 1382 1383 - static void arm_smmu_init_bypass_stes(__le64 *strtab, unsigned int nent) 1383 + static void arm_smmu_init_bypass_stes(__le64 *strtab, unsigned int nent, bool force) 1384 1384 { 1385 1385 unsigned int i; 1386 + u64 val = STRTAB_STE_0_V; 1387 + 1388 + if (disable_bypass && !force) 1389 + val |= FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_ABORT); 1390 + else 1391 + val |= FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_BYPASS); 1386 1392 1387 1393 for (i = 0; i < nent; ++i) { 1388 - arm_smmu_write_strtab_ent(NULL, -1, strtab); 1394 + strtab[0] = cpu_to_le64(val); 1395 + strtab[1] = cpu_to_le64(FIELD_PREP(STRTAB_STE_1_SHCFG, 1396 + STRTAB_STE_1_SHCFG_INCOMING)); 1397 + strtab[2] = 0; 1389 1398 strtab += STRTAB_STE_DWORDS; 1390 1399 } 1391 1400 } ··· 1422 1413 return -ENOMEM; 1423 1414 } 1424 1415 1425 - arm_smmu_init_bypass_stes(desc->l2ptr, 1 << STRTAB_SPLIT); 1416 + arm_smmu_init_bypass_stes(desc->l2ptr, 1 << STRTAB_SPLIT, false); 1426 1417 arm_smmu_write_strtab_l1_desc(strtab, desc); 1427 1418 return 0; 1428 1419 } ··· 2546 2537 return sid < limit; 2547 2538 } 2548 2539 2540 + static int arm_smmu_init_sid_strtab(struct arm_smmu_device *smmu, u32 sid) 2541 + { 2542 + /* Check the SIDs are in range of the SMMU and our stream table */ 2543 + if (!arm_smmu_sid_in_range(smmu, sid)) 2544 + return -ERANGE; 2545 + 2546 + /* Ensure l2 strtab is initialised */ 2547 + if (smmu->features & ARM_SMMU_FEAT_2_LVL_STRTAB) 2548 + return arm_smmu_init_l2_strtab(smmu, sid); 2549 + 2550 + return 0; 2551 + } 2552 + 2549 2553 static int arm_smmu_insert_master(struct arm_smmu_device *smmu, 2550 2554 struct arm_smmu_master *master) 2551 2555 { ··· 2582 2560 new_stream->id = sid; 2583 2561 new_stream->master = master; 2584 2562 2585 - /* 2586 - * Check the SIDs are in range of the SMMU and our stream table 2587 - */ 2588 - if (!arm_smmu_sid_in_range(smmu, sid)) { 2589 - ret = -ERANGE; 2563 + ret = arm_smmu_init_sid_strtab(smmu, sid); 2564 + if (ret) 2590 2565 break; 2591 - } 2592 - 2593 - /* Ensure l2 strtab is initialised */ 2594 - if (smmu->features & ARM_SMMU_FEAT_2_LVL_STRTAB) { 2595 - ret = arm_smmu_init_l2_strtab(smmu, sid); 2596 - if (ret) 2597 - break; 2598 - } 2599 2566 2600 2567 /* Insert into SID tree */ 2601 2568 new_node = &(smmu->streams.rb_node); ··· 2702 2691 2703 2692 static void arm_smmu_release_device(struct device *dev) 2704 2693 { 2705 - struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); 2706 - struct arm_smmu_master *master; 2694 + struct arm_smmu_master *master = dev_iommu_priv_get(dev); 2707 2695 2708 - if (!fwspec || fwspec->ops != &arm_smmu_ops) 2709 - return; 2710 - 2711 - master = dev_iommu_priv_get(dev); 2712 2696 if (WARN_ON(arm_smmu_master_sva_enabled(master))) 2713 2697 iopf_queue_remove_device(master->smmu->evtq.iopf, dev); 2714 2698 arm_smmu_detach_dev(master); 2715 2699 arm_smmu_disable_pasid(master); 2716 2700 arm_smmu_remove_master(master); 2717 2701 kfree(master); 2718 - iommu_fwspec_free(dev); 2719 2702 } 2720 2703 2721 2704 static struct iommu_group *arm_smmu_device_group(struct device *dev) ··· 2765 2760 iommu_dma_get_resv_regions(dev, head); 2766 2761 } 2767 2762 2768 - static bool arm_smmu_dev_has_feature(struct device *dev, 2769 - enum iommu_dev_features feat) 2770 - { 2771 - struct arm_smmu_master *master = dev_iommu_priv_get(dev); 2772 - 2773 - if (!master) 2774 - return false; 2775 - 2776 - switch (feat) { 2777 - case IOMMU_DEV_FEAT_IOPF: 2778 - return arm_smmu_master_iopf_supported(master); 2779 - case IOMMU_DEV_FEAT_SVA: 2780 - return arm_smmu_master_sva_supported(master); 2781 - default: 2782 - return false; 2783 - } 2784 - } 2785 - 2786 - static bool arm_smmu_dev_feature_enabled(struct device *dev, 2787 - enum iommu_dev_features feat) 2788 - { 2789 - struct arm_smmu_master *master = dev_iommu_priv_get(dev); 2790 - 2791 - if (!master) 2792 - return false; 2793 - 2794 - switch (feat) { 2795 - case IOMMU_DEV_FEAT_IOPF: 2796 - return master->iopf_enabled; 2797 - case IOMMU_DEV_FEAT_SVA: 2798 - return arm_smmu_master_sva_enabled(master); 2799 - default: 2800 - return false; 2801 - } 2802 - } 2803 - 2804 2763 static int arm_smmu_dev_enable_feature(struct device *dev, 2805 2764 enum iommu_dev_features feat) 2806 2765 { 2807 2766 struct arm_smmu_master *master = dev_iommu_priv_get(dev); 2808 2767 2809 - if (!arm_smmu_dev_has_feature(dev, feat)) 2768 + if (!master) 2810 2769 return -ENODEV; 2811 - 2812 - if (arm_smmu_dev_feature_enabled(dev, feat)) 2813 - return -EBUSY; 2814 2770 2815 2771 switch (feat) { 2816 2772 case IOMMU_DEV_FEAT_IOPF: 2773 + if (!arm_smmu_master_iopf_supported(master)) 2774 + return -EINVAL; 2775 + if (master->iopf_enabled) 2776 + return -EBUSY; 2817 2777 master->iopf_enabled = true; 2818 2778 return 0; 2819 2779 case IOMMU_DEV_FEAT_SVA: 2780 + if (!arm_smmu_master_sva_supported(master)) 2781 + return -EINVAL; 2782 + if (arm_smmu_master_sva_enabled(master)) 2783 + return -EBUSY; 2820 2784 return arm_smmu_master_enable_sva(master); 2821 2785 default: 2822 2786 return -EINVAL; ··· 2797 2823 { 2798 2824 struct arm_smmu_master *master = dev_iommu_priv_get(dev); 2799 2825 2800 - if (!arm_smmu_dev_feature_enabled(dev, feat)) 2826 + if (!master) 2801 2827 return -EINVAL; 2802 2828 2803 2829 switch (feat) { 2804 2830 case IOMMU_DEV_FEAT_IOPF: 2831 + if (!master->iopf_enabled) 2832 + return -EINVAL; 2805 2833 if (master->sva_enabled) 2806 2834 return -EBUSY; 2807 2835 master->iopf_enabled = false; 2808 2836 return 0; 2809 2837 case IOMMU_DEV_FEAT_SVA: 2838 + if (!arm_smmu_master_sva_enabled(master)) 2839 + return -EINVAL; 2810 2840 return arm_smmu_master_disable_sva(master); 2811 2841 default: 2812 2842 return -EINVAL; ··· 2825 2847 .device_group = arm_smmu_device_group, 2826 2848 .of_xlate = arm_smmu_of_xlate, 2827 2849 .get_resv_regions = arm_smmu_get_resv_regions, 2828 - .put_resv_regions = generic_iommu_put_resv_regions, 2829 - .dev_has_feat = arm_smmu_dev_has_feature, 2830 - .dev_feat_enabled = arm_smmu_dev_feature_enabled, 2831 2850 .dev_enable_feat = arm_smmu_dev_enable_feature, 2832 2851 .dev_disable_feat = arm_smmu_dev_disable_feature, 2833 2852 .sva_bind = arm_smmu_sva_bind, ··· 3024 3049 reg |= FIELD_PREP(STRTAB_BASE_CFG_LOG2SIZE, smmu->sid_bits); 3025 3050 cfg->strtab_base_cfg = reg; 3026 3051 3027 - arm_smmu_init_bypass_stes(strtab, cfg->num_l1_ents); 3052 + arm_smmu_init_bypass_stes(strtab, cfg->num_l1_ents, false); 3028 3053 return 0; 3029 3054 } 3030 3055 ··· 3718 3743 return devm_ioremap_resource(dev, &res); 3719 3744 } 3720 3745 3746 + static void arm_smmu_rmr_install_bypass_ste(struct arm_smmu_device *smmu) 3747 + { 3748 + struct list_head rmr_list; 3749 + struct iommu_resv_region *e; 3750 + 3751 + INIT_LIST_HEAD(&rmr_list); 3752 + iort_get_rmr_sids(dev_fwnode(smmu->dev), &rmr_list); 3753 + 3754 + list_for_each_entry(e, &rmr_list, list) { 3755 + __le64 *step; 3756 + struct iommu_iort_rmr_data *rmr; 3757 + int ret, i; 3758 + 3759 + rmr = container_of(e, struct iommu_iort_rmr_data, rr); 3760 + for (i = 0; i < rmr->num_sids; i++) { 3761 + ret = arm_smmu_init_sid_strtab(smmu, rmr->sids[i]); 3762 + if (ret) { 3763 + dev_err(smmu->dev, "RMR SID(0x%x) bypass failed\n", 3764 + rmr->sids[i]); 3765 + continue; 3766 + } 3767 + 3768 + step = arm_smmu_get_step_for_sid(smmu, rmr->sids[i]); 3769 + arm_smmu_init_bypass_stes(step, 1, true); 3770 + } 3771 + } 3772 + 3773 + iort_put_rmr_sids(dev_fwnode(smmu->dev), &rmr_list); 3774 + } 3775 + 3721 3776 static int arm_smmu_device_probe(struct platform_device *pdev) 3722 3777 { 3723 3778 int irq, ret; ··· 3830 3825 3831 3826 /* Record our private device structure */ 3832 3827 platform_set_drvdata(pdev, smmu); 3828 + 3829 + /* Check for RMRs and install bypass STEs if any */ 3830 + arm_smmu_rmr_install_bypass_ste(smmu); 3833 3831 3834 3832 /* Reset the device */ 3835 3833 ret = arm_smmu_device_reset(smmu, bypass);
+1
drivers/iommu/arm/arm-smmu/Makefile
··· 3 3 obj-$(CONFIG_ARM_SMMU) += arm_smmu.o 4 4 arm_smmu-objs += arm-smmu.o arm-smmu-impl.o arm-smmu-nvidia.o 5 5 arm_smmu-$(CONFIG_ARM_SMMU_QCOM) += arm-smmu-qcom.o 6 + arm_smmu-$(CONFIG_ARM_SMMU_QCOM_DEBUG) += arm-smmu-qcom-debug.o
+142
drivers/iommu/arm/arm-smmu/arm-smmu-qcom-debug.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. 4 + */ 5 + 6 + #include <linux/of_device.h> 7 + #include <linux/qcom_scm.h> 8 + #include <linux/ratelimit.h> 9 + 10 + #include "arm-smmu.h" 11 + #include "arm-smmu-qcom.h" 12 + 13 + enum qcom_smmu_impl_reg_offset { 14 + QCOM_SMMU_TBU_PWR_STATUS, 15 + QCOM_SMMU_STATS_SYNC_INV_TBU_ACK, 16 + QCOM_SMMU_MMU2QSS_AND_SAFE_WAIT_CNTR, 17 + }; 18 + 19 + struct qcom_smmu_config { 20 + const u32 *reg_offset; 21 + }; 22 + 23 + void qcom_smmu_tlb_sync_debug(struct arm_smmu_device *smmu) 24 + { 25 + int ret; 26 + u32 tbu_pwr_status, sync_inv_ack, sync_inv_progress; 27 + struct qcom_smmu *qsmmu = container_of(smmu, struct qcom_smmu, smmu); 28 + const struct qcom_smmu_config *cfg; 29 + static DEFINE_RATELIMIT_STATE(rs, DEFAULT_RATELIMIT_INTERVAL, 30 + DEFAULT_RATELIMIT_BURST); 31 + 32 + if (__ratelimit(&rs)) { 33 + dev_err(smmu->dev, "TLB sync timed out -- SMMU may be deadlocked\n"); 34 + 35 + cfg = qsmmu->cfg; 36 + if (!cfg) 37 + return; 38 + 39 + ret = qcom_scm_io_readl(smmu->ioaddr + cfg->reg_offset[QCOM_SMMU_TBU_PWR_STATUS], 40 + &tbu_pwr_status); 41 + if (ret) 42 + dev_err(smmu->dev, 43 + "Failed to read TBU power status: %d\n", ret); 44 + 45 + ret = qcom_scm_io_readl(smmu->ioaddr + cfg->reg_offset[QCOM_SMMU_STATS_SYNC_INV_TBU_ACK], 46 + &sync_inv_ack); 47 + if (ret) 48 + dev_err(smmu->dev, 49 + "Failed to read TBU sync/inv ack status: %d\n", ret); 50 + 51 + ret = qcom_scm_io_readl(smmu->ioaddr + cfg->reg_offset[QCOM_SMMU_MMU2QSS_AND_SAFE_WAIT_CNTR], 52 + &sync_inv_progress); 53 + if (ret) 54 + dev_err(smmu->dev, 55 + "Failed to read TCU syn/inv progress: %d\n", ret); 56 + 57 + dev_err(smmu->dev, 58 + "TBU: power_status %#x sync_inv_ack %#x sync_inv_progress %#x\n", 59 + tbu_pwr_status, sync_inv_ack, sync_inv_progress); 60 + } 61 + } 62 + 63 + /* Implementation Defined Register Space 0 register offsets */ 64 + static const u32 qcom_smmu_impl0_reg_offset[] = { 65 + [QCOM_SMMU_TBU_PWR_STATUS] = 0x2204, 66 + [QCOM_SMMU_STATS_SYNC_INV_TBU_ACK] = 0x25dc, 67 + [QCOM_SMMU_MMU2QSS_AND_SAFE_WAIT_CNTR] = 0x2670, 68 + }; 69 + 70 + static const struct qcom_smmu_config qcm2290_smmu_cfg = { 71 + .reg_offset = qcom_smmu_impl0_reg_offset, 72 + }; 73 + 74 + static const struct qcom_smmu_config sc7180_smmu_cfg = { 75 + .reg_offset = qcom_smmu_impl0_reg_offset, 76 + }; 77 + 78 + static const struct qcom_smmu_config sc7280_smmu_cfg = { 79 + .reg_offset = qcom_smmu_impl0_reg_offset, 80 + }; 81 + 82 + static const struct qcom_smmu_config sc8180x_smmu_cfg = { 83 + .reg_offset = qcom_smmu_impl0_reg_offset, 84 + }; 85 + 86 + static const struct qcom_smmu_config sc8280xp_smmu_cfg = { 87 + .reg_offset = qcom_smmu_impl0_reg_offset, 88 + }; 89 + 90 + static const struct qcom_smmu_config sm6125_smmu_cfg = { 91 + .reg_offset = qcom_smmu_impl0_reg_offset, 92 + }; 93 + 94 + static const struct qcom_smmu_config sm6350_smmu_cfg = { 95 + .reg_offset = qcom_smmu_impl0_reg_offset, 96 + }; 97 + 98 + static const struct qcom_smmu_config sm8150_smmu_cfg = { 99 + .reg_offset = qcom_smmu_impl0_reg_offset, 100 + }; 101 + 102 + static const struct qcom_smmu_config sm8250_smmu_cfg = { 103 + .reg_offset = qcom_smmu_impl0_reg_offset, 104 + }; 105 + 106 + static const struct qcom_smmu_config sm8350_smmu_cfg = { 107 + .reg_offset = qcom_smmu_impl0_reg_offset, 108 + }; 109 + 110 + static const struct qcom_smmu_config sm8450_smmu_cfg = { 111 + .reg_offset = qcom_smmu_impl0_reg_offset, 112 + }; 113 + 114 + static const struct of_device_id __maybe_unused qcom_smmu_impl_debug_match[] = { 115 + { .compatible = "qcom,msm8998-smmu-v2" }, 116 + { .compatible = "qcom,qcm2290-smmu-500", .data = &qcm2290_smmu_cfg }, 117 + { .compatible = "qcom,sc7180-smmu-500", .data = &sc7180_smmu_cfg }, 118 + { .compatible = "qcom,sc7280-smmu-500", .data = &sc7280_smmu_cfg}, 119 + { .compatible = "qcom,sc8180x-smmu-500", .data = &sc8180x_smmu_cfg }, 120 + { .compatible = "qcom,sc8280xp-smmu-500", .data = &sc8280xp_smmu_cfg }, 121 + { .compatible = "qcom,sdm630-smmu-v2" }, 122 + { .compatible = "qcom,sdm845-smmu-500" }, 123 + { .compatible = "qcom,sm6125-smmu-500", .data = &sm6125_smmu_cfg}, 124 + { .compatible = "qcom,sm6350-smmu-500", .data = &sm6350_smmu_cfg}, 125 + { .compatible = "qcom,sm8150-smmu-500", .data = &sm8150_smmu_cfg }, 126 + { .compatible = "qcom,sm8250-smmu-500", .data = &sm8250_smmu_cfg }, 127 + { .compatible = "qcom,sm8350-smmu-500", .data = &sm8350_smmu_cfg }, 128 + { .compatible = "qcom,sm8450-smmu-500", .data = &sm8450_smmu_cfg }, 129 + { } 130 + }; 131 + 132 + const void *qcom_smmu_impl_data(struct arm_smmu_device *smmu) 133 + { 134 + const struct of_device_id *match; 135 + const struct device_node *np = smmu->dev->of_node; 136 + 137 + match = of_match_node(qcom_smmu_impl_debug_match, np); 138 + if (!match) 139 + return NULL; 140 + 141 + return match->data; 142 + }
+28 -6
drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c
··· 5 5 6 6 #include <linux/acpi.h> 7 7 #include <linux/adreno-smmu-priv.h> 8 + #include <linux/delay.h> 8 9 #include <linux/of_device.h> 9 10 #include <linux/qcom_scm.h> 10 11 11 12 #include "arm-smmu.h" 13 + #include "arm-smmu-qcom.h" 12 14 13 - struct qcom_smmu { 14 - struct arm_smmu_device smmu; 15 - bool bypass_quirk; 16 - u8 bypass_cbndx; 17 - u32 stall_enabled; 18 - }; 15 + #define QCOM_DUMMY_VAL -1 19 16 20 17 static struct qcom_smmu *to_qcom_smmu(struct arm_smmu_device *smmu) 21 18 { 22 19 return container_of(smmu, struct qcom_smmu, smmu); 20 + } 21 + 22 + static void qcom_smmu_tlb_sync(struct arm_smmu_device *smmu, int page, 23 + int sync, int status) 24 + { 25 + unsigned int spin_cnt, delay; 26 + u32 reg; 27 + 28 + arm_smmu_writel(smmu, page, sync, QCOM_DUMMY_VAL); 29 + for (delay = 1; delay < TLB_LOOP_TIMEOUT; delay *= 2) { 30 + for (spin_cnt = TLB_SPIN_COUNT; spin_cnt > 0; spin_cnt--) { 31 + reg = arm_smmu_readl(smmu, page, status); 32 + if (!(reg & ARM_SMMU_sTLBGSTATUS_GSACTIVE)) 33 + return; 34 + cpu_relax(); 35 + } 36 + udelay(delay); 37 + } 38 + 39 + qcom_smmu_tlb_sync_debug(smmu); 23 40 } 24 41 25 42 static void qcom_adreno_smmu_write_sctlr(struct arm_smmu_device *smmu, int idx, ··· 250 233 { .compatible = "qcom,sc7280-mdss" }, 251 234 { .compatible = "qcom,sc7280-mss-pil" }, 252 235 { .compatible = "qcom,sc8180x-mdss" }, 236 + { .compatible = "qcom,sm8250-mdss" }, 253 237 { .compatible = "qcom,sdm845-mdss" }, 254 238 { .compatible = "qcom,sdm845-mss-pil" }, 255 239 { } ··· 392 374 .def_domain_type = qcom_smmu_def_domain_type, 393 375 .reset = qcom_smmu500_reset, 394 376 .write_s2cr = qcom_smmu_write_s2cr, 377 + .tlb_sync = qcom_smmu_tlb_sync, 395 378 }; 396 379 397 380 static const struct arm_smmu_impl qcom_adreno_smmu_impl = { ··· 401 382 .reset = qcom_smmu500_reset, 402 383 .alloc_context_bank = qcom_adreno_smmu_alloc_context_bank, 403 384 .write_sctlr = qcom_adreno_smmu_write_sctlr, 385 + .tlb_sync = qcom_smmu_tlb_sync, 404 386 }; 405 387 406 388 static struct arm_smmu_device *qcom_smmu_create(struct arm_smmu_device *smmu, ··· 418 398 return ERR_PTR(-ENOMEM); 419 399 420 400 qsmmu->smmu.impl = impl; 401 + qsmmu->cfg = qcom_smmu_impl_data(smmu); 421 402 422 403 return &qsmmu->smmu; 423 404 } ··· 434 413 { .compatible = "qcom,sdm845-smmu-500" }, 435 414 { .compatible = "qcom,sm6125-smmu-500" }, 436 415 { .compatible = "qcom,sm6350-smmu-500" }, 416 + { .compatible = "qcom,sm6375-smmu-500" }, 437 417 { .compatible = "qcom,sm8150-smmu-500" }, 438 418 { .compatible = "qcom,sm8250-smmu-500" }, 439 419 { .compatible = "qcom,sm8350-smmu-500" },
+28
drivers/iommu/arm/arm-smmu/arm-smmu-qcom.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-only */ 2 + /* 3 + * Copyright (c) 2022, Qualcomm Innovation Center, Inc. All rights reserved. 4 + */ 5 + 6 + #ifndef _ARM_SMMU_QCOM_H 7 + #define _ARM_SMMU_QCOM_H 8 + 9 + struct qcom_smmu { 10 + struct arm_smmu_device smmu; 11 + const struct qcom_smmu_config *cfg; 12 + bool bypass_quirk; 13 + u8 bypass_cbndx; 14 + u32 stall_enabled; 15 + }; 16 + 17 + #ifdef CONFIG_ARM_SMMU_QCOM_DEBUG 18 + void qcom_smmu_tlb_sync_debug(struct arm_smmu_device *smmu); 19 + const void *qcom_smmu_impl_data(struct arm_smmu_device *smmu); 20 + #else 21 + static inline void qcom_smmu_tlb_sync_debug(struct arm_smmu_device *smmu) { } 22 + static inline const void *qcom_smmu_impl_data(struct arm_smmu_device *smmu) 23 + { 24 + return NULL; 25 + } 26 + #endif 27 + 28 + #endif /* _ARM_SMMU_QCOM_H */
+58 -15
drivers/iommu/arm/arm-smmu/arm-smmu.c
··· 1432 1432 static void arm_smmu_release_device(struct device *dev) 1433 1433 { 1434 1434 struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); 1435 - struct arm_smmu_master_cfg *cfg; 1436 - struct arm_smmu_device *smmu; 1435 + struct arm_smmu_master_cfg *cfg = dev_iommu_priv_get(dev); 1437 1436 int ret; 1438 1437 1439 - if (!fwspec || fwspec->ops != &arm_smmu_ops) 1440 - return; 1441 - 1442 - cfg = dev_iommu_priv_get(dev); 1443 - smmu = cfg->smmu; 1444 - 1445 - ret = arm_smmu_rpm_get(smmu); 1438 + ret = arm_smmu_rpm_get(cfg->smmu); 1446 1439 if (ret < 0) 1447 1440 return; 1448 1441 1449 1442 arm_smmu_master_free_smes(cfg, fwspec); 1450 1443 1451 - arm_smmu_rpm_put(smmu); 1444 + arm_smmu_rpm_put(cfg->smmu); 1452 1445 1453 1446 dev_iommu_priv_set(dev, NULL); 1454 1447 kfree(cfg); 1455 - iommu_fwspec_free(dev); 1456 1448 } 1457 1449 1458 1450 static void arm_smmu_probe_finalize(struct device *dev) ··· 1584 1592 .device_group = arm_smmu_device_group, 1585 1593 .of_xlate = arm_smmu_of_xlate, 1586 1594 .get_resv_regions = arm_smmu_get_resv_regions, 1587 - .put_resv_regions = generic_iommu_put_resv_regions, 1588 1595 .def_domain_type = arm_smmu_def_domain_type, 1589 1596 .pgsize_bitmap = -1UL, /* Restricted during device attach */ 1590 1597 .owner = THIS_MODULE, ··· 2062 2071 return err; 2063 2072 } 2064 2073 2074 + static void arm_smmu_rmr_install_bypass_smr(struct arm_smmu_device *smmu) 2075 + { 2076 + struct list_head rmr_list; 2077 + struct iommu_resv_region *e; 2078 + int idx, cnt = 0; 2079 + u32 reg; 2080 + 2081 + INIT_LIST_HEAD(&rmr_list); 2082 + iort_get_rmr_sids(dev_fwnode(smmu->dev), &rmr_list); 2083 + 2084 + /* 2085 + * Rather than trying to look at existing mappings that 2086 + * are setup by the firmware and then invalidate the ones 2087 + * that do no have matching RMR entries, just disable the 2088 + * SMMU until it gets enabled again in the reset routine. 2089 + */ 2090 + reg = arm_smmu_gr0_read(smmu, ARM_SMMU_GR0_sCR0); 2091 + reg |= ARM_SMMU_sCR0_CLIENTPD; 2092 + arm_smmu_gr0_write(smmu, ARM_SMMU_GR0_sCR0, reg); 2093 + 2094 + list_for_each_entry(e, &rmr_list, list) { 2095 + struct iommu_iort_rmr_data *rmr; 2096 + int i; 2097 + 2098 + rmr = container_of(e, struct iommu_iort_rmr_data, rr); 2099 + for (i = 0; i < rmr->num_sids; i++) { 2100 + idx = arm_smmu_find_sme(smmu, rmr->sids[i], ~0); 2101 + if (idx < 0) 2102 + continue; 2103 + 2104 + if (smmu->s2crs[idx].count == 0) { 2105 + smmu->smrs[idx].id = rmr->sids[i]; 2106 + smmu->smrs[idx].mask = 0; 2107 + smmu->smrs[idx].valid = true; 2108 + } 2109 + smmu->s2crs[idx].count++; 2110 + smmu->s2crs[idx].type = S2CR_TYPE_BYPASS; 2111 + smmu->s2crs[idx].privcfg = S2CR_PRIVCFG_DEFAULT; 2112 + 2113 + cnt++; 2114 + } 2115 + } 2116 + 2117 + dev_notice(smmu->dev, "\tpreserved %d boot mapping%s\n", cnt, 2118 + cnt == 1 ? "" : "s"); 2119 + iort_put_rmr_sids(dev_fwnode(smmu->dev), &rmr_list); 2120 + } 2121 + 2065 2122 static int arm_smmu_device_probe(struct platform_device *pdev) 2066 2123 { 2067 2124 struct resource *res; 2068 - resource_size_t ioaddr; 2069 2125 struct arm_smmu_device *smmu; 2070 2126 struct device *dev = &pdev->dev; 2071 2127 int num_irqs, i, err; ··· 2136 2098 smmu->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); 2137 2099 if (IS_ERR(smmu->base)) 2138 2100 return PTR_ERR(smmu->base); 2139 - ioaddr = res->start; 2101 + smmu->ioaddr = res->start; 2102 + 2140 2103 /* 2141 2104 * The resource size should effectively match the value of SMMU_TOP; 2142 2105 * stash that temporarily until we know PAGESIZE to validate it with. ··· 2217 2178 } 2218 2179 2219 2180 err = iommu_device_sysfs_add(&smmu->iommu, smmu->dev, NULL, 2220 - "smmu.%pa", &ioaddr); 2181 + "smmu.%pa", &smmu->ioaddr); 2221 2182 if (err) { 2222 2183 dev_err(dev, "Failed to register iommu in sysfs\n"); 2223 2184 return err; ··· 2230 2191 } 2231 2192 2232 2193 platform_set_drvdata(pdev, smmu); 2194 + 2195 + /* Check for RMRs and install bypass SMRs if any */ 2196 + arm_smmu_rmr_install_bypass_smr(smmu); 2197 + 2233 2198 arm_smmu_device_reset(smmu); 2234 2199 arm_smmu_test_smr_masks(smmu); 2235 2200
+1
drivers/iommu/arm/arm-smmu/arm-smmu.h
··· 278 278 struct device *dev; 279 279 280 280 void __iomem *base; 281 + phys_addr_t ioaddr; 281 282 unsigned int numpage; 282 283 unsigned int pgshift; 283 284
+5 -13
drivers/iommu/arm/arm-smmu/qcom_iommu.c
··· 532 532 return &qcom_iommu->iommu; 533 533 } 534 534 535 - static void qcom_iommu_release_device(struct device *dev) 536 - { 537 - struct qcom_iommu_dev *qcom_iommu = to_iommu(dev); 538 - 539 - if (!qcom_iommu) 540 - return; 541 - 542 - iommu_fwspec_free(dev); 543 - } 544 - 545 535 static int qcom_iommu_of_xlate(struct device *dev, struct of_phandle_args *args) 546 536 { 547 537 struct qcom_iommu_dev *qcom_iommu; ··· 581 591 .capable = qcom_iommu_capable, 582 592 .domain_alloc = qcom_iommu_domain_alloc, 583 593 .probe_device = qcom_iommu_probe_device, 584 - .release_device = qcom_iommu_release_device, 585 594 .device_group = generic_device_group, 586 595 .of_xlate = qcom_iommu_of_xlate, 587 596 .pgsize_bitmap = SZ_4K | SZ_64K | SZ_1M | SZ_16M, ··· 739 750 { 740 751 struct device_node *child; 741 752 742 - for_each_child_of_node(qcom_iommu->dev->of_node, child) 743 - if (of_device_is_compatible(child, "qcom,msm-iommu-v1-sec")) 753 + for_each_child_of_node(qcom_iommu->dev->of_node, child) { 754 + if (of_device_is_compatible(child, "qcom,msm-iommu-v1-sec")) { 755 + of_node_put(child); 744 756 return true; 757 + } 758 + } 745 759 746 760 return false; 747 761 }
+15 -6
drivers/iommu/dma-iommu.c
··· 64 64 65 65 /* Domain for flush queue callback; NULL if flush queue not in use */ 66 66 struct iommu_domain *fq_domain; 67 + struct mutex mutex; 67 68 }; 68 69 69 70 static DEFINE_STATIC_KEY_FALSE(iommu_deferred_attach_enabled); 70 - bool iommu_dma_forcedac __read_mostly; 71 + bool iommu_dma_forcedac __read_mostly = !IS_ENABLED(CONFIG_IOMMU_DMA_PCI_SAC); 71 72 72 73 static int __init iommu_dma_forcedac_setup(char *str) 73 74 { ··· 311 310 if (!domain->iova_cookie) 312 311 return -ENOMEM; 313 312 313 + mutex_init(&domain->iova_cookie->mutex); 314 314 return 0; 315 315 } 316 316 ··· 387 385 { 388 386 389 387 if (!is_of_node(dev_iommu_fwspec_get(dev)->iommu_fwnode)) 390 - iort_iommu_msi_get_resv_regions(dev, list); 388 + iort_iommu_get_resv_regions(dev, list); 391 389 392 390 } 393 391 EXPORT_SYMBOL(iommu_dma_get_resv_regions); ··· 562 560 } 563 561 564 562 /* start_pfn is always nonzero for an already-initialised domain */ 563 + mutex_lock(&cookie->mutex); 565 564 if (iovad->start_pfn) { 566 565 if (1UL << order != iovad->granule || 567 566 base_pfn != iovad->start_pfn) { 568 567 pr_warn("Incompatible range for DMA domain\n"); 569 - return -EFAULT; 568 + ret = -EFAULT; 569 + goto done_unlock; 570 570 } 571 571 572 - return 0; 572 + ret = 0; 573 + goto done_unlock; 573 574 } 574 575 575 576 init_iova_domain(iovad, 1UL << order, base_pfn); 576 577 ret = iova_domain_init_rcaches(iovad); 577 578 if (ret) 578 - return ret; 579 + goto done_unlock; 579 580 580 581 /* If the FQ fails we can simply fall back to strict mode */ 581 582 if (domain->type == IOMMU_DOMAIN_DMA_FQ && iommu_dma_init_fq(domain)) 582 583 domain->type = IOMMU_DOMAIN_DMA; 583 584 584 - return iova_reserve_iommu_regions(dev, domain); 585 + ret = iova_reserve_iommu_regions(dev, domain); 586 + 587 + done_unlock: 588 + mutex_unlock(&cookie->mutex); 589 + return ret; 585 590 } 586 591 587 592 /**
+138 -48
drivers/iommu/exynos-iommu.c
··· 135 135 #define CFG_SYSSEL (1 << 22) /* System MMU 3.2 only */ 136 136 #define CFG_FLPDCACHE (1 << 20) /* System MMU 3.2+ only */ 137 137 138 + #define CTRL_VM_ENABLE BIT(0) 139 + #define CTRL_VM_FAULT_MODE_STALL BIT(3) 140 + #define CAPA0_CAPA1_EXIST BIT(11) 141 + #define CAPA1_VCR_ENABLED BIT(14) 142 + 138 143 /* common registers */ 139 144 #define REG_MMU_CTRL 0x000 140 145 #define REG_MMU_CFG 0x004 ··· 153 148 #define MAKE_MMU_VER(maj, min) ((((maj) & 0xF) << 7) | ((min) & 0x7F)) 154 149 155 150 /* v1.x - v3.x registers */ 156 - #define REG_MMU_FLUSH 0x00C 157 - #define REG_MMU_FLUSH_ENTRY 0x010 158 - #define REG_PT_BASE_ADDR 0x014 159 - #define REG_INT_STATUS 0x018 160 - #define REG_INT_CLEAR 0x01C 161 - 162 151 #define REG_PAGE_FAULT_ADDR 0x024 163 152 #define REG_AW_FAULT_ADDR 0x028 164 153 #define REG_AR_FAULT_ADDR 0x02C 165 154 #define REG_DEFAULT_SLAVE_ADDR 0x030 166 155 167 156 /* v5.x registers */ 168 - #define REG_V5_PT_BASE_PFN 0x00C 169 - #define REG_V5_MMU_FLUSH_ALL 0x010 170 - #define REG_V5_MMU_FLUSH_ENTRY 0x014 171 - #define REG_V5_MMU_FLUSH_RANGE 0x018 172 - #define REG_V5_MMU_FLUSH_START 0x020 173 - #define REG_V5_MMU_FLUSH_END 0x024 174 - #define REG_V5_INT_STATUS 0x060 175 - #define REG_V5_INT_CLEAR 0x064 176 157 #define REG_V5_FAULT_AR_VA 0x070 177 158 #define REG_V5_FAULT_AW_VA 0x080 159 + 160 + /* v7.x registers */ 161 + #define REG_V7_CAPA0 0x870 162 + #define REG_V7_CAPA1 0x874 163 + #define REG_V7_CTRL_VM 0x8000 178 164 179 165 #define has_sysmmu(dev) (dev_iommu_priv_get(dev) != NULL) 180 166 ··· 247 251 }; 248 252 249 253 /* 254 + * SysMMU version specific data. Contains offsets for the registers which can 255 + * be found in different SysMMU variants, but have different offset values. 256 + */ 257 + struct sysmmu_variant { 258 + u32 pt_base; /* page table base address (physical) */ 259 + u32 flush_all; /* invalidate all TLB entries */ 260 + u32 flush_entry; /* invalidate specific TLB entry */ 261 + u32 flush_range; /* invalidate TLB entries in specified range */ 262 + u32 flush_start; /* start address of range invalidation */ 263 + u32 flush_end; /* end address of range invalidation */ 264 + u32 int_status; /* interrupt status information */ 265 + u32 int_clear; /* clear the interrupt */ 266 + }; 267 + 268 + /* 250 269 * This structure hold all data of a single SYSMMU controller, this includes 251 270 * hw resources like registers and clocks, pointers and list nodes to connect 252 271 * it to all other structures, internal state and parameters read from device ··· 285 274 unsigned int version; /* our version */ 286 275 287 276 struct iommu_device iommu; /* IOMMU core handle */ 277 + const struct sysmmu_variant *variant; /* version specific data */ 278 + 279 + /* v7 fields */ 280 + bool has_vcr; /* virtual machine control register */ 281 + }; 282 + 283 + #define SYSMMU_REG(data, reg) ((data)->sfrbase + (data)->variant->reg) 284 + 285 + /* SysMMU v1..v3 */ 286 + static const struct sysmmu_variant sysmmu_v1_variant = { 287 + .flush_all = 0x0c, 288 + .flush_entry = 0x10, 289 + .pt_base = 0x14, 290 + .int_status = 0x18, 291 + .int_clear = 0x1c, 292 + }; 293 + 294 + /* SysMMU v5 and v7 (non-VM capable) */ 295 + static const struct sysmmu_variant sysmmu_v5_variant = { 296 + .pt_base = 0x0c, 297 + .flush_all = 0x10, 298 + .flush_entry = 0x14, 299 + .flush_range = 0x18, 300 + .flush_start = 0x20, 301 + .flush_end = 0x24, 302 + .int_status = 0x60, 303 + .int_clear = 0x64, 304 + }; 305 + 306 + /* SysMMU v7: VM capable register set */ 307 + static const struct sysmmu_variant sysmmu_v7_vm_variant = { 308 + .pt_base = 0x800c, 309 + .flush_all = 0x8010, 310 + .flush_entry = 0x8014, 311 + .flush_range = 0x8018, 312 + .flush_start = 0x8020, 313 + .flush_end = 0x8024, 314 + .int_status = 0x60, 315 + .int_clear = 0x64, 288 316 }; 289 317 290 318 static struct exynos_iommu_domain *to_exynos_domain(struct iommu_domain *dom) ··· 354 304 355 305 static void __sysmmu_tlb_invalidate(struct sysmmu_drvdata *data) 356 306 { 357 - if (MMU_MAJ_VER(data->version) < 5) 358 - writel(0x1, data->sfrbase + REG_MMU_FLUSH); 359 - else 360 - writel(0x1, data->sfrbase + REG_V5_MMU_FLUSH_ALL); 307 + writel(0x1, SYSMMU_REG(data, flush_all)); 361 308 } 362 309 363 310 static void __sysmmu_tlb_invalidate_entry(struct sysmmu_drvdata *data, ··· 362 315 { 363 316 unsigned int i; 364 317 365 - if (MMU_MAJ_VER(data->version) < 5) { 318 + if (MMU_MAJ_VER(data->version) < 5 || num_inv == 1) { 366 319 for (i = 0; i < num_inv; i++) { 367 320 writel((iova & SPAGE_MASK) | 1, 368 - data->sfrbase + REG_MMU_FLUSH_ENTRY); 321 + SYSMMU_REG(data, flush_entry)); 369 322 iova += SPAGE_SIZE; 370 323 } 371 324 } else { 372 - if (num_inv == 1) { 373 - writel((iova & SPAGE_MASK) | 1, 374 - data->sfrbase + REG_V5_MMU_FLUSH_ENTRY); 375 - } else { 376 - writel((iova & SPAGE_MASK), 377 - data->sfrbase + REG_V5_MMU_FLUSH_START); 378 - writel((iova & SPAGE_MASK) + (num_inv - 1) * SPAGE_SIZE, 379 - data->sfrbase + REG_V5_MMU_FLUSH_END); 380 - writel(1, data->sfrbase + REG_V5_MMU_FLUSH_RANGE); 381 - } 325 + writel(iova & SPAGE_MASK, SYSMMU_REG(data, flush_start)); 326 + writel((iova & SPAGE_MASK) + (num_inv - 1) * SPAGE_SIZE, 327 + SYSMMU_REG(data, flush_end)); 328 + writel(0x1, SYSMMU_REG(data, flush_range)); 382 329 } 383 330 } 384 331 385 332 static void __sysmmu_set_ptbase(struct sysmmu_drvdata *data, phys_addr_t pgd) 386 333 { 387 - if (MMU_MAJ_VER(data->version) < 5) 388 - writel(pgd, data->sfrbase + REG_PT_BASE_ADDR); 389 - else 390 - writel(pgd >> PAGE_SHIFT, 391 - data->sfrbase + REG_V5_PT_BASE_PFN); 334 + u32 pt_base; 392 335 336 + if (MMU_MAJ_VER(data->version) < 5) 337 + pt_base = pgd; 338 + else 339 + pt_base = pgd >> SPAGE_ORDER; 340 + 341 + writel(pt_base, SYSMMU_REG(data, pt_base)); 393 342 __sysmmu_tlb_invalidate(data); 394 343 } 395 344 ··· 405 362 clk_disable_unprepare(data->clk_master); 406 363 } 407 364 365 + static bool __sysmmu_has_capa1(struct sysmmu_drvdata *data) 366 + { 367 + u32 capa0 = readl(data->sfrbase + REG_V7_CAPA0); 368 + 369 + return capa0 & CAPA0_CAPA1_EXIST; 370 + } 371 + 372 + static void __sysmmu_get_vcr(struct sysmmu_drvdata *data) 373 + { 374 + u32 capa1 = readl(data->sfrbase + REG_V7_CAPA1); 375 + 376 + data->has_vcr = capa1 & CAPA1_VCR_ENABLED; 377 + } 378 + 408 379 static void __sysmmu_get_version(struct sysmmu_drvdata *data) 409 380 { 410 381 u32 ver; ··· 435 378 436 379 dev_dbg(data->sysmmu, "hardware version: %d.%d\n", 437 380 MMU_MAJ_VER(data->version), MMU_MIN_VER(data->version)); 381 + 382 + if (MMU_MAJ_VER(data->version) < 5) { 383 + data->variant = &sysmmu_v1_variant; 384 + } else if (MMU_MAJ_VER(data->version) < 7) { 385 + data->variant = &sysmmu_v5_variant; 386 + } else { 387 + if (__sysmmu_has_capa1(data)) 388 + __sysmmu_get_vcr(data); 389 + if (data->has_vcr) 390 + data->variant = &sysmmu_v7_vm_variant; 391 + else 392 + data->variant = &sysmmu_v5_variant; 393 + } 438 394 439 395 __sysmmu_disable_clocks(data); 440 396 } ··· 476 406 const struct sysmmu_fault_info *finfo; 477 407 unsigned int i, n, itype; 478 408 sysmmu_iova_t fault_addr; 479 - unsigned short reg_status, reg_clear; 480 409 int ret = -ENOSYS; 481 410 482 411 WARN_ON(!data->active); 483 412 484 413 if (MMU_MAJ_VER(data->version) < 5) { 485 - reg_status = REG_INT_STATUS; 486 - reg_clear = REG_INT_CLEAR; 487 414 finfo = sysmmu_faults; 488 415 n = ARRAY_SIZE(sysmmu_faults); 489 416 } else { 490 - reg_status = REG_V5_INT_STATUS; 491 - reg_clear = REG_V5_INT_CLEAR; 492 417 finfo = sysmmu_v5_faults; 493 418 n = ARRAY_SIZE(sysmmu_v5_faults); 494 419 } ··· 492 427 493 428 clk_enable(data->clk_master); 494 429 495 - itype = __ffs(readl(data->sfrbase + reg_status)); 430 + itype = __ffs(readl(SYSMMU_REG(data, int_status))); 496 431 for (i = 0; i < n; i++, finfo++) 497 432 if (finfo->bit == itype) 498 433 break; ··· 509 444 /* fault is not recovered by fault handler */ 510 445 BUG_ON(ret != 0); 511 446 512 - writel(1 << itype, data->sfrbase + reg_clear); 447 + writel(1 << itype, SYSMMU_REG(data, int_clear)); 513 448 514 449 sysmmu_unblock(data); 515 450 ··· 551 486 writel(cfg, data->sfrbase + REG_MMU_CFG); 552 487 } 553 488 489 + static void __sysmmu_enable_vid(struct sysmmu_drvdata *data) 490 + { 491 + u32 ctrl; 492 + 493 + if (MMU_MAJ_VER(data->version) < 7 || !data->has_vcr) 494 + return; 495 + 496 + ctrl = readl(data->sfrbase + REG_V7_CTRL_VM); 497 + ctrl |= CTRL_VM_ENABLE | CTRL_VM_FAULT_MODE_STALL; 498 + writel(ctrl, data->sfrbase + REG_V7_CTRL_VM); 499 + } 500 + 554 501 static void __sysmmu_enable(struct sysmmu_drvdata *data) 555 502 { 556 503 unsigned long flags; ··· 573 496 writel(CTRL_BLOCK, data->sfrbase + REG_MMU_CTRL); 574 497 __sysmmu_init_config(data); 575 498 __sysmmu_set_ptbase(data, data->pgtable); 499 + __sysmmu_enable_vid(data); 576 500 writel(CTRL_ENABLE, data->sfrbase + REG_MMU_CTRL); 577 501 data->active = true; 578 502 spin_unlock_irqrestore(&data->lock, flags); ··· 629 551 * 64KB page can be one of 16 consecutive sets. 630 552 */ 631 553 if (MMU_MAJ_VER(data->version) == 2) 632 - num_inv = min_t(unsigned int, size / PAGE_SIZE, 64); 554 + num_inv = min_t(unsigned int, size / SPAGE_SIZE, 64); 633 555 634 556 if (sysmmu_block(data)) { 635 557 __sysmmu_tlb_invalidate_entry(data, iova, num_inv); ··· 701 623 data->sysmmu = dev; 702 624 spin_lock_init(&data->lock); 703 625 626 + __sysmmu_get_version(data); 627 + 704 628 ret = iommu_device_sysfs_add(&data->iommu, &pdev->dev, NULL, 705 629 dev_name(data->sysmmu)); 706 630 if (ret) ··· 710 630 711 631 ret = iommu_device_register(&data->iommu, &exynos_iommu_ops, dev); 712 632 if (ret) 713 - return ret; 633 + goto err_iommu_register; 714 634 715 635 platform_set_drvdata(pdev, data); 716 636 717 - __sysmmu_get_version(data); 718 637 if (PG_ENT_SHIFT < 0) { 719 638 if (MMU_MAJ_VER(data->version) < 5) { 720 639 PG_ENT_SHIFT = SYSMMU_PG_ENT_SHIFT; ··· 723 644 PG_ENT_SHIFT = SYSMMU_V5_PG_ENT_SHIFT; 724 645 LV1_PROT = SYSMMU_V5_LV1_PROT; 725 646 LV2_PROT = SYSMMU_V5_LV2_PROT; 647 + } 648 + } 649 + 650 + if (MMU_MAJ_VER(data->version) >= 5) { 651 + ret = dma_set_mask(dev, DMA_BIT_MASK(36)); 652 + if (ret) { 653 + dev_err(dev, "Unable to set DMA mask: %d\n", ret); 654 + goto err_dma_set_mask; 726 655 } 727 656 } 728 657 ··· 744 657 pm_runtime_enable(dev); 745 658 746 659 return 0; 660 + 661 + err_dma_set_mask: 662 + iommu_device_unregister(&data->iommu); 663 + err_iommu_register: 664 + iommu_device_sysfs_remove(&data->iommu); 665 + return ret; 747 666 } 748 667 749 668 static int __maybe_unused exynos_sysmmu_suspend(struct device *dev) ··· 1343 1250 { 1344 1251 struct exynos_iommu_owner *owner = dev_iommu_priv_get(dev); 1345 1252 struct sysmmu_drvdata *data; 1346 - 1347 - if (!has_sysmmu(dev)) 1348 - return; 1349 1253 1350 1254 if (owner->domain) { 1351 1255 struct iommu_group *group = iommu_group_get(dev);
-5
drivers/iommu/fsl_pamu_domain.c
··· 447 447 return &pamu_iommu; 448 448 } 449 449 450 - static void fsl_pamu_release_device(struct device *dev) 451 - { 452 - } 453 - 454 450 static const struct iommu_ops fsl_pamu_ops = { 455 451 .capable = fsl_pamu_capable, 456 452 .domain_alloc = fsl_pamu_domain_alloc, 457 453 .probe_device = fsl_pamu_probe_device, 458 - .release_device = fsl_pamu_release_device, 459 454 .device_group = fsl_pamu_device_group, 460 455 .default_domain_ops = &(const struct iommu_domain_ops) { 461 456 .attach_dev = fsl_pamu_attach_device,
+1 -1
drivers/iommu/intel/cap_audit.c
··· 10 10 11 11 #define pr_fmt(fmt) "DMAR: " fmt 12 12 13 - #include <linux/intel-iommu.h> 13 + #include "iommu.h" 14 14 #include "cap_audit.h" 15 15 16 16 static u64 intel_iommu_cap_sanity;
+34 -17
drivers/iommu/intel/debugfs.c
··· 10 10 11 11 #include <linux/debugfs.h> 12 12 #include <linux/dmar.h> 13 - #include <linux/intel-iommu.h> 14 13 #include <linux/pci.h> 15 14 16 15 #include <asm/irq_remapping.h> 17 16 17 + #include "iommu.h" 18 18 #include "pasid.h" 19 19 #include "perf.h" 20 20 ··· 263 263 264 264 static void root_tbl_walk(struct seq_file *m, struct intel_iommu *iommu) 265 265 { 266 - unsigned long flags; 267 266 u16 bus; 268 267 269 - spin_lock_irqsave(&iommu->lock, flags); 268 + spin_lock(&iommu->lock); 270 269 seq_printf(m, "IOMMU %s: Root Table Address: 0x%llx\n", iommu->name, 271 270 (u64)virt_to_phys(iommu->root_entry)); 272 271 seq_puts(m, "B.D.F\tRoot_entry\t\t\t\tContext_entry\t\t\t\tPASID\tPASID_table_entry\n"); ··· 277 278 */ 278 279 for (bus = 0; bus < 256; bus++) 279 280 ctx_tbl_walk(m, iommu, bus); 280 - 281 - spin_unlock_irqrestore(&iommu->lock, flags); 281 + spin_unlock(&iommu->lock); 282 282 } 283 283 284 284 static int dmar_translation_struct_show(struct seq_file *m, void *unused) ··· 340 342 } 341 343 } 342 344 343 - static int show_device_domain_translation(struct device *dev, void *data) 345 + static int __show_device_domain_translation(struct device *dev, void *data) 344 346 { 345 - struct device_domain_info *info = dev_iommu_priv_get(dev); 346 - struct dmar_domain *domain = info->domain; 347 + struct dmar_domain *domain; 347 348 struct seq_file *m = data; 348 349 u64 path[6] = { 0 }; 349 350 351 + domain = to_dmar_domain(iommu_get_domain_for_dev(dev)); 350 352 if (!domain) 351 353 return 0; 352 354 ··· 357 359 pgtable_walk_level(m, domain->pgd, domain->agaw + 2, 0, path); 358 360 seq_putc(m, '\n'); 359 361 362 + /* Don't iterate */ 363 + return 1; 364 + } 365 + 366 + static int show_device_domain_translation(struct device *dev, void *data) 367 + { 368 + struct iommu_group *group; 369 + 370 + group = iommu_group_get(dev); 371 + if (group) { 372 + /* 373 + * The group->mutex is held across the callback, which will 374 + * block calls to iommu_attach/detach_group/device. Hence, 375 + * the domain of the device will not change during traversal. 376 + * 377 + * All devices in an iommu group share a single domain, hence 378 + * we only dump the domain of the first device. Even though, 379 + * this code still possibly races with the iommu_unmap() 380 + * interface. This could be solved by RCU-freeing the page 381 + * table pages in the iommu_unmap() path. 382 + */ 383 + iommu_group_for_each_dev(group, data, 384 + __show_device_domain_translation); 385 + iommu_group_put(group); 386 + } 387 + 360 388 return 0; 361 389 } 362 390 363 391 static int domain_translation_struct_show(struct seq_file *m, void *unused) 364 392 { 365 - unsigned long flags; 366 - int ret; 367 - 368 - spin_lock_irqsave(&device_domain_lock, flags); 369 - ret = bus_for_each_dev(&pci_bus_type, NULL, m, 370 - show_device_domain_translation); 371 - spin_unlock_irqrestore(&device_domain_lock, flags); 372 - 373 - return ret; 393 + return bus_for_each_dev(&pci_bus_type, NULL, m, 394 + show_device_domain_translation); 374 395 } 375 396 DEFINE_SHOW_ATTRIBUTE(domain_translation_struct); 376 397
+10 -29
drivers/iommu/intel/dmar.c
··· 19 19 #include <linux/pci.h> 20 20 #include <linux/dmar.h> 21 21 #include <linux/iova.h> 22 - #include <linux/intel-iommu.h> 23 22 #include <linux/timer.h> 24 23 #include <linux/irq.h> 25 24 #include <linux/interrupt.h> ··· 29 30 #include <linux/numa.h> 30 31 #include <linux/limits.h> 31 32 #include <asm/irq_remapping.h> 32 - #include <trace/events/intel_iommu.h> 33 33 34 + #include "iommu.h" 34 35 #include "../irq_remapping.h" 35 36 #include "perf.h" 37 + #include "trace.h" 36 38 37 39 typedef int (*dmar_res_handler_t)(struct acpi_dmar_header *, void *); 38 40 struct dmar_res_callback { ··· 60 60 61 61 struct acpi_table_header * __initdata dmar_tbl; 62 62 static int dmar_dev_scope_status = 1; 63 - static unsigned long dmar_seq_ids[BITS_TO_LONGS(DMAR_UNITS_SUPPORTED)]; 63 + static DEFINE_IDA(dmar_seq_ids); 64 64 65 65 static int alloc_iommu(struct dmar_drhd_unit *drhd); 66 66 static void free_iommu(struct intel_iommu *iommu); ··· 1023 1023 return err; 1024 1024 } 1025 1025 1026 - static int dmar_alloc_seq_id(struct intel_iommu *iommu) 1027 - { 1028 - iommu->seq_id = find_first_zero_bit(dmar_seq_ids, 1029 - DMAR_UNITS_SUPPORTED); 1030 - if (iommu->seq_id >= DMAR_UNITS_SUPPORTED) { 1031 - iommu->seq_id = -1; 1032 - } else { 1033 - set_bit(iommu->seq_id, dmar_seq_ids); 1034 - sprintf(iommu->name, "dmar%d", iommu->seq_id); 1035 - } 1036 - 1037 - return iommu->seq_id; 1038 - } 1039 - 1040 - static void dmar_free_seq_id(struct intel_iommu *iommu) 1041 - { 1042 - if (iommu->seq_id >= 0) { 1043 - clear_bit(iommu->seq_id, dmar_seq_ids); 1044 - iommu->seq_id = -1; 1045 - } 1046 - } 1047 - 1048 1026 static int alloc_iommu(struct dmar_drhd_unit *drhd) 1049 1027 { 1050 1028 struct intel_iommu *iommu; ··· 1040 1062 if (!iommu) 1041 1063 return -ENOMEM; 1042 1064 1043 - if (dmar_alloc_seq_id(iommu) < 0) { 1065 + iommu->seq_id = ida_alloc_range(&dmar_seq_ids, 0, 1066 + DMAR_UNITS_SUPPORTED - 1, GFP_KERNEL); 1067 + if (iommu->seq_id < 0) { 1044 1068 pr_err("Failed to allocate seq_id\n"); 1045 - err = -ENOSPC; 1069 + err = iommu->seq_id; 1046 1070 goto error; 1047 1071 } 1072 + sprintf(iommu->name, "dmar%d", iommu->seq_id); 1048 1073 1049 1074 err = map_iommu(iommu, drhd->reg_base_addr); 1050 1075 if (err) { ··· 1131 1150 err_unmap: 1132 1151 unmap_iommu(iommu); 1133 1152 error_free_seq_id: 1134 - dmar_free_seq_id(iommu); 1153 + ida_free(&dmar_seq_ids, iommu->seq_id); 1135 1154 error: 1136 1155 kfree(iommu); 1137 1156 return err; ··· 1164 1183 if (iommu->reg) 1165 1184 unmap_iommu(iommu); 1166 1185 1167 - dmar_free_seq_id(iommu); 1186 + ida_free(&dmar_seq_ids, iommu->seq_id); 1168 1187 kfree(iommu); 1169 1188 } 1170 1189
+154 -297
drivers/iommu/intel/iommu.c
··· 17 17 #include <linux/dma-direct.h> 18 18 #include <linux/dma-iommu.h> 19 19 #include <linux/dmi.h> 20 - #include <linux/intel-iommu.h> 21 20 #include <linux/intel-svm.h> 22 21 #include <linux/memory.h> 23 22 #include <linux/pci.h> ··· 25 26 #include <linux/syscore_ops.h> 26 27 #include <linux/tboot.h> 27 28 29 + #include "iommu.h" 28 30 #include "../irq_remapping.h" 29 31 #include "../iommu-sva-lib.h" 30 32 #include "pasid.h" ··· 126 126 return page_to_dma_pfn(virt_to_page(p)); 127 127 } 128 128 129 - /* global iommu list, set NULL for ignored DMAR units */ 130 - static struct intel_iommu **g_iommus; 131 - 132 129 static void __init check_tylersburg_isoch(void); 133 130 static int rwbf_quirk; 134 - static inline struct device_domain_info * 135 - dmar_search_domain_by_dev_info(int segment, int bus, int devfn); 136 131 137 132 /* 138 133 * set to 1 to panic kernel if can't successfully enable VT-d ··· 251 256 static struct dmar_domain *si_domain; 252 257 static int hw_pass_through = 1; 253 258 254 - #define for_each_domain_iommu(idx, domain) \ 255 - for (idx = 0; idx < g_num_of_iommus; idx++) \ 256 - if (domain->iommu_refcnt[idx]) 257 - 258 259 struct dmar_rmrr_unit { 259 260 struct list_head list; /* list of rmrr units */ 260 261 struct acpi_dmar_header *hdr; /* ACPI header */ ··· 284 293 #define for_each_rmrr_units(rmrr) \ 285 294 list_for_each_entry(rmrr, &dmar_rmrr_units, list) 286 295 287 - /* bitmap for indexing intel_iommus */ 288 - static int g_num_of_iommus; 289 - 290 - static void domain_remove_dev_info(struct dmar_domain *domain); 291 296 static void dmar_remove_one_dev_info(struct device *dev); 292 - static void __dmar_remove_one_dev_info(struct device_domain_info *info); 293 297 294 298 int dmar_disabled = !IS_ENABLED(CONFIG_INTEL_IOMMU_DEFAULT_ON); 295 299 int intel_iommu_sm = IS_ENABLED(CONFIG_INTEL_IOMMU_SCALABLE_MODE_DEFAULT_ON); ··· 299 313 300 314 #define IDENTMAP_GFX 2 301 315 #define IDENTMAP_AZALIA 4 302 - 303 - int intel_iommu_gfx_mapped; 304 - EXPORT_SYMBOL_GPL(intel_iommu_gfx_mapped); 305 - 306 - DEFINE_SPINLOCK(device_domain_lock); 307 - static LIST_HEAD(device_domain_list); 308 316 309 317 const struct iommu_ops intel_iommu_ops; 310 318 ··· 435 455 return __iommu_calculate_agaw(iommu, DEFAULT_DOMAIN_ADDRESS_WIDTH); 436 456 } 437 457 438 - /* This functionin only returns single iommu in a domain */ 439 - struct intel_iommu *domain_get_iommu(struct dmar_domain *domain) 440 - { 441 - int iommu_id; 442 - 443 - /* si_domain and vm domain should not get here. */ 444 - if (WARN_ON(!iommu_is_dma_domain(&domain->domain))) 445 - return NULL; 446 - 447 - for_each_domain_iommu(iommu_id, domain) 448 - break; 449 - 450 - if (iommu_id < 0 || iommu_id >= g_num_of_iommus) 451 - return NULL; 452 - 453 - return g_iommus[iommu_id]; 454 - } 455 - 456 458 static inline bool iommu_paging_structure_coherency(struct intel_iommu *iommu) 457 459 { 458 460 return sm_supported(iommu) ? ··· 443 481 444 482 static void domain_update_iommu_coherency(struct dmar_domain *domain) 445 483 { 484 + struct iommu_domain_info *info; 446 485 struct dmar_drhd_unit *drhd; 447 486 struct intel_iommu *iommu; 448 487 bool found = false; 449 - int i; 488 + unsigned long i; 450 489 451 490 domain->iommu_coherency = true; 452 - 453 - for_each_domain_iommu(i, domain) { 491 + xa_for_each(&domain->iommu_array, i, info) { 454 492 found = true; 455 - if (!iommu_paging_structure_coherency(g_iommus[i])) { 493 + if (!iommu_paging_structure_coherency(info->iommu)) { 456 494 domain->iommu_coherency = false; 457 495 break; 458 496 } ··· 506 544 struct device_domain_info *info; 507 545 int nid = NUMA_NO_NODE; 508 546 509 - assert_spin_locked(&device_domain_lock); 510 - 511 - if (list_empty(&domain->devices)) 512 - return NUMA_NO_NODE; 513 - 547 + spin_lock(&domain->lock); 514 548 list_for_each_entry(info, &domain->devices, link) { 515 - if (!info->dev) 516 - continue; 517 - 518 549 /* 519 550 * There could possibly be multiple device numa nodes as devices 520 551 * within the same domain may sit behind different IOMMUs. There ··· 518 563 if (nid != NUMA_NO_NODE) 519 564 break; 520 565 } 566 + spin_unlock(&domain->lock); 521 567 522 568 return nid; 523 569 } ··· 760 804 { 761 805 struct context_entry *context; 762 806 int ret = 0; 763 - unsigned long flags; 764 807 765 - spin_lock_irqsave(&iommu->lock, flags); 808 + spin_lock(&iommu->lock); 766 809 context = iommu_context_addr(iommu, bus, devfn, 0); 767 810 if (context) 768 811 ret = context_present(context); 769 - spin_unlock_irqrestore(&iommu->lock, flags); 812 + spin_unlock(&iommu->lock); 770 813 return ret; 771 814 } 772 815 773 816 static void free_context_table(struct intel_iommu *iommu) 774 817 { 775 - int i; 776 - unsigned long flags; 777 818 struct context_entry *context; 819 + int i; 778 820 779 - spin_lock_irqsave(&iommu->lock, flags); 780 - if (!iommu->root_entry) { 781 - goto out; 782 - } 821 + if (!iommu->root_entry) 822 + return; 823 + 783 824 for (i = 0; i < ROOT_ENTRY_NR; i++) { 784 825 context = iommu_context_addr(iommu, i, 0, 0); 785 826 if (context) ··· 788 835 context = iommu_context_addr(iommu, i, 0x80, 0); 789 836 if (context) 790 837 free_pgtable_page(context); 791 - 792 838 } 839 + 793 840 free_pgtable_page(iommu->root_entry); 794 841 iommu->root_entry = NULL; 795 - out: 796 - spin_unlock_irqrestore(&iommu->lock, flags); 797 842 } 798 843 799 844 #ifdef CONFIG_DMAR_DEBUG ··· 800 849 struct device_domain_info *info; 801 850 struct dma_pte *parent, *pte; 802 851 struct dmar_domain *domain; 852 + struct pci_dev *pdev; 803 853 int offset, level; 804 854 805 - info = dmar_search_domain_by_dev_info(iommu->segment, bus, devfn); 855 + pdev = pci_get_domain_bus_and_slot(iommu->segment, bus, devfn); 856 + if (!pdev) 857 + return; 858 + 859 + info = dev_iommu_priv_get(&pdev->dev); 806 860 if (!info || !info->domain) { 807 861 pr_info("device [%02x:%02x.%d] not probed\n", 808 862 bus, PCI_SLOT(devfn), PCI_FUNC(devfn)); ··· 1190 1234 static int iommu_alloc_root_entry(struct intel_iommu *iommu) 1191 1235 { 1192 1236 struct root_entry *root; 1193 - unsigned long flags; 1194 1237 1195 1238 root = (struct root_entry *)alloc_pgtable_page(iommu->node); 1196 1239 if (!root) { ··· 1199 1244 } 1200 1245 1201 1246 __iommu_flush_cache(iommu, root, ROOT_SIZE); 1202 - 1203 - spin_lock_irqsave(&iommu->lock, flags); 1204 1247 iommu->root_entry = root; 1205 - spin_unlock_irqrestore(&iommu->lock, flags); 1206 1248 1207 1249 return 0; 1208 1250 } ··· 1341 1389 } 1342 1390 1343 1391 static struct device_domain_info * 1344 - iommu_support_dev_iotlb (struct dmar_domain *domain, struct intel_iommu *iommu, 1345 - u8 bus, u8 devfn) 1392 + iommu_support_dev_iotlb(struct dmar_domain *domain, struct intel_iommu *iommu, 1393 + u8 bus, u8 devfn) 1346 1394 { 1347 1395 struct device_domain_info *info; 1348 - 1349 - assert_spin_locked(&device_domain_lock); 1350 1396 1351 1397 if (!iommu->qi) 1352 1398 return NULL; 1353 1399 1354 - list_for_each_entry(info, &domain->devices, link) 1400 + spin_lock(&domain->lock); 1401 + list_for_each_entry(info, &domain->devices, link) { 1355 1402 if (info->iommu == iommu && info->bus == bus && 1356 1403 info->devfn == devfn) { 1357 - if (info->ats_supported && info->dev) 1358 - return info; 1359 - break; 1404 + spin_unlock(&domain->lock); 1405 + return info->ats_supported ? info : NULL; 1360 1406 } 1407 + } 1408 + spin_unlock(&domain->lock); 1361 1409 1362 1410 return NULL; 1363 1411 } ··· 1367 1415 struct device_domain_info *info; 1368 1416 bool has_iotlb_device = false; 1369 1417 1370 - assert_spin_locked(&device_domain_lock); 1371 - 1372 - list_for_each_entry(info, &domain->devices, link) 1418 + spin_lock(&domain->lock); 1419 + list_for_each_entry(info, &domain->devices, link) { 1373 1420 if (info->ats_enabled) { 1374 1421 has_iotlb_device = true; 1375 1422 break; 1376 1423 } 1377 - 1424 + } 1378 1425 domain->has_iotlb_device = has_iotlb_device; 1426 + spin_unlock(&domain->lock); 1379 1427 } 1380 1428 1381 1429 static void iommu_enable_dev_iotlb(struct device_domain_info *info) 1382 1430 { 1383 1431 struct pci_dev *pdev; 1384 - 1385 - assert_spin_locked(&device_domain_lock); 1386 1432 1387 1433 if (!info || !dev_is_pci(info->dev)) 1388 1434 return; ··· 1427 1477 { 1428 1478 struct pci_dev *pdev; 1429 1479 1430 - assert_spin_locked(&device_domain_lock); 1431 - 1432 1480 if (!dev_is_pci(info->dev)) 1433 1481 return; 1434 1482 ··· 1466 1518 static void iommu_flush_dev_iotlb(struct dmar_domain *domain, 1467 1519 u64 addr, unsigned mask) 1468 1520 { 1469 - unsigned long flags; 1470 1521 struct device_domain_info *info; 1471 1522 1472 1523 if (!domain->has_iotlb_device) 1473 1524 return; 1474 1525 1475 - spin_lock_irqsave(&device_domain_lock, flags); 1526 + spin_lock(&domain->lock); 1476 1527 list_for_each_entry(info, &domain->devices, link) 1477 1528 __iommu_flush_dev_iotlb(info, addr, mask); 1478 - 1479 - spin_unlock_irqrestore(&device_domain_lock, flags); 1529 + spin_unlock(&domain->lock); 1480 1530 } 1481 1531 1482 1532 static void iommu_flush_iotlb_psi(struct intel_iommu *iommu, ··· 1485 1539 unsigned int aligned_pages = __roundup_pow_of_two(pages); 1486 1540 unsigned int mask = ilog2(aligned_pages); 1487 1541 uint64_t addr = (uint64_t)pfn << VTD_PAGE_SHIFT; 1488 - u16 did = domain->iommu_did[iommu->seq_id]; 1542 + u16 did = domain_id_iommu(domain, iommu); 1489 1543 1490 1544 BUG_ON(pages == 0); 1491 1545 ··· 1555 1609 static void intel_flush_iotlb_all(struct iommu_domain *domain) 1556 1610 { 1557 1611 struct dmar_domain *dmar_domain = to_dmar_domain(domain); 1558 - int idx; 1612 + struct iommu_domain_info *info; 1613 + unsigned long idx; 1559 1614 1560 - for_each_domain_iommu(idx, dmar_domain) { 1561 - struct intel_iommu *iommu = g_iommus[idx]; 1562 - u16 did = dmar_domain->iommu_did[iommu->seq_id]; 1615 + xa_for_each(&dmar_domain->iommu_array, idx, info) { 1616 + struct intel_iommu *iommu = info->iommu; 1617 + u16 did = domain_id_iommu(dmar_domain, iommu); 1563 1618 1564 1619 if (domain_use_first_level(dmar_domain)) 1565 1620 qi_flush_piotlb(iommu, did, PASID_RID2PASID, 0, -1, 0); ··· 1666 1719 1667 1720 static void disable_dmar_iommu(struct intel_iommu *iommu) 1668 1721 { 1669 - struct device_domain_info *info, *tmp; 1670 - unsigned long flags; 1671 - 1672 1722 if (!iommu->domain_ids) 1673 1723 return; 1674 1724 1675 - spin_lock_irqsave(&device_domain_lock, flags); 1676 - list_for_each_entry_safe(info, tmp, &device_domain_list, global) { 1677 - if (info->iommu != iommu) 1678 - continue; 1679 - 1680 - if (!info->dev || !info->domain) 1681 - continue; 1682 - 1683 - __dmar_remove_one_dev_info(info); 1684 - } 1685 - spin_unlock_irqrestore(&device_domain_lock, flags); 1725 + /* 1726 + * All iommu domains must have been detached from the devices, 1727 + * hence there should be no domain IDs in use. 1728 + */ 1729 + if (WARN_ON(bitmap_weight(iommu->domain_ids, cap_ndoms(iommu->cap)) 1730 + > NUM_RESERVED_DID)) 1731 + return; 1686 1732 1687 1733 if (iommu->gcmd & DMA_GCMD_TE) 1688 1734 iommu_disable_translation(iommu); ··· 1687 1747 bitmap_free(iommu->domain_ids); 1688 1748 iommu->domain_ids = NULL; 1689 1749 } 1690 - 1691 - g_iommus[iommu->seq_id] = NULL; 1692 1750 1693 1751 /* free context mapping */ 1694 1752 free_context_table(iommu); ··· 1733 1795 domain->flags |= DOMAIN_FLAG_USE_FIRST_LEVEL; 1734 1796 domain->has_iotlb_device = false; 1735 1797 INIT_LIST_HEAD(&domain->devices); 1798 + spin_lock_init(&domain->lock); 1799 + xa_init(&domain->iommu_array); 1736 1800 1737 1801 return domain; 1738 1802 } 1739 1803 1740 - /* Must be called with iommu->lock */ 1741 1804 static int domain_attach_iommu(struct dmar_domain *domain, 1742 1805 struct intel_iommu *iommu) 1743 1806 { 1807 + struct iommu_domain_info *info, *curr; 1744 1808 unsigned long ndomains; 1745 - int num; 1809 + int num, ret = -ENOSPC; 1746 1810 1747 - assert_spin_locked(&device_domain_lock); 1748 - assert_spin_locked(&iommu->lock); 1811 + info = kzalloc(sizeof(*info), GFP_KERNEL); 1812 + if (!info) 1813 + return -ENOMEM; 1749 1814 1750 - domain->iommu_refcnt[iommu->seq_id] += 1; 1751 - if (domain->iommu_refcnt[iommu->seq_id] == 1) { 1752 - ndomains = cap_ndoms(iommu->cap); 1753 - num = find_first_zero_bit(iommu->domain_ids, ndomains); 1754 - 1755 - if (num >= ndomains) { 1756 - pr_err("%s: No free domain ids\n", iommu->name); 1757 - domain->iommu_refcnt[iommu->seq_id] -= 1; 1758 - return -ENOSPC; 1759 - } 1760 - 1761 - set_bit(num, iommu->domain_ids); 1762 - domain->iommu_did[iommu->seq_id] = num; 1763 - domain->nid = iommu->node; 1764 - domain_update_iommu_cap(domain); 1815 + spin_lock(&iommu->lock); 1816 + curr = xa_load(&domain->iommu_array, iommu->seq_id); 1817 + if (curr) { 1818 + curr->refcnt++; 1819 + spin_unlock(&iommu->lock); 1820 + kfree(info); 1821 + return 0; 1765 1822 } 1766 1823 1824 + ndomains = cap_ndoms(iommu->cap); 1825 + num = find_first_zero_bit(iommu->domain_ids, ndomains); 1826 + if (num >= ndomains) { 1827 + pr_err("%s: No free domain ids\n", iommu->name); 1828 + goto err_unlock; 1829 + } 1830 + 1831 + set_bit(num, iommu->domain_ids); 1832 + info->refcnt = 1; 1833 + info->did = num; 1834 + info->iommu = iommu; 1835 + curr = xa_cmpxchg(&domain->iommu_array, iommu->seq_id, 1836 + NULL, info, GFP_ATOMIC); 1837 + if (curr) { 1838 + ret = xa_err(curr) ? : -EBUSY; 1839 + goto err_clear; 1840 + } 1841 + domain_update_iommu_cap(domain); 1842 + 1843 + spin_unlock(&iommu->lock); 1767 1844 return 0; 1845 + 1846 + err_clear: 1847 + clear_bit(info->did, iommu->domain_ids); 1848 + err_unlock: 1849 + spin_unlock(&iommu->lock); 1850 + kfree(info); 1851 + return ret; 1768 1852 } 1769 1853 1770 1854 static void domain_detach_iommu(struct dmar_domain *domain, 1771 1855 struct intel_iommu *iommu) 1772 1856 { 1773 - int num; 1857 + struct iommu_domain_info *info; 1774 1858 1775 - assert_spin_locked(&device_domain_lock); 1776 - assert_spin_locked(&iommu->lock); 1777 - 1778 - domain->iommu_refcnt[iommu->seq_id] -= 1; 1779 - if (domain->iommu_refcnt[iommu->seq_id] == 0) { 1780 - num = domain->iommu_did[iommu->seq_id]; 1781 - clear_bit(num, iommu->domain_ids); 1859 + spin_lock(&iommu->lock); 1860 + info = xa_load(&domain->iommu_array, iommu->seq_id); 1861 + if (--info->refcnt == 0) { 1862 + clear_bit(info->did, iommu->domain_ids); 1863 + xa_erase(&domain->iommu_array, iommu->seq_id); 1864 + domain->nid = NUMA_NO_NODE; 1782 1865 domain_update_iommu_cap(domain); 1783 - domain->iommu_did[iommu->seq_id] = 0; 1866 + kfree(info); 1784 1867 } 1868 + spin_unlock(&iommu->lock); 1785 1869 } 1786 1870 1787 1871 static inline int guestwidth_to_adjustwidth(int gaw) ··· 1822 1862 1823 1863 static void domain_exit(struct dmar_domain *domain) 1824 1864 { 1825 - 1826 - /* Remove associated devices and clear attached or cached domains */ 1827 - domain_remove_dev_info(domain); 1828 - 1829 1865 if (domain->pgd) { 1830 1866 LIST_HEAD(freelist); 1831 1867 1832 1868 domain_unmap(domain, 0, DOMAIN_MAX_PFN(domain->gaw), &freelist); 1833 1869 put_pages_list(&freelist); 1834 1870 } 1871 + 1872 + if (WARN_ON(!list_empty(&domain->devices))) 1873 + return; 1835 1874 1836 1875 kfree(domain); 1837 1876 } ··· 1889 1930 struct pasid_table *table, 1890 1931 u8 bus, u8 devfn) 1891 1932 { 1892 - u16 did = domain->iommu_did[iommu->seq_id]; 1933 + struct device_domain_info *info = 1934 + iommu_support_dev_iotlb(domain, iommu, bus, devfn); 1935 + u16 did = domain_id_iommu(domain, iommu); 1893 1936 int translation = CONTEXT_TT_MULTI_LEVEL; 1894 - struct device_domain_info *info = NULL; 1895 1937 struct context_entry *context; 1896 - unsigned long flags; 1897 1938 int ret; 1898 1939 1899 1940 WARN_ON(did == 0); ··· 1906 1947 1907 1948 BUG_ON(!domain->pgd); 1908 1949 1909 - spin_lock_irqsave(&device_domain_lock, flags); 1910 1950 spin_lock(&iommu->lock); 1911 - 1912 1951 ret = -ENOMEM; 1913 1952 context = iommu_context_addr(iommu, bus, devfn, 1); 1914 1953 if (!context) ··· 1957 2000 * Setup the Device-TLB enable bit and Page request 1958 2001 * Enable bit: 1959 2002 */ 1960 - info = iommu_support_dev_iotlb(domain, iommu, bus, devfn); 1961 2003 if (info && info->ats_supported) 1962 2004 context_set_sm_dte(context); 1963 2005 if (info && info->pri_supported) ··· 1979 2023 goto out_unlock; 1980 2024 } 1981 2025 1982 - info = iommu_support_dev_iotlb(domain, iommu, bus, devfn); 1983 2026 if (info && info->ats_supported) 1984 2027 translation = CONTEXT_TT_DEV_IOTLB; 1985 2028 else ··· 2024 2069 2025 2070 out_unlock: 2026 2071 spin_unlock(&iommu->lock); 2027 - spin_unlock_irqrestore(&device_domain_lock, flags); 2028 2072 2029 2073 return ret; 2030 2074 } ··· 2140 2186 unsigned long end_pfn, int level) 2141 2187 { 2142 2188 unsigned long lvl_pages = lvl_to_nr_pages(level); 2189 + struct iommu_domain_info *info; 2143 2190 struct dma_pte *pte = NULL; 2144 - int i; 2191 + unsigned long i; 2145 2192 2146 2193 while (start_pfn <= end_pfn) { 2147 2194 if (!pte) ··· 2153 2198 start_pfn + lvl_pages - 1, 2154 2199 level + 1); 2155 2200 2156 - for_each_domain_iommu(i, domain) 2157 - iommu_flush_iotlb_psi(g_iommus[i], domain, 2201 + xa_for_each(&domain->iommu_array, i, info) 2202 + iommu_flush_iotlb_psi(info->iommu, domain, 2158 2203 start_pfn, lvl_pages, 2159 2204 0, 0); 2160 2205 } ··· 2268 2313 { 2269 2314 struct intel_iommu *iommu = info->iommu; 2270 2315 struct context_entry *context; 2271 - unsigned long flags; 2272 2316 u16 did_old; 2273 2317 2274 2318 if (!iommu) 2275 2319 return; 2276 2320 2277 - spin_lock_irqsave(&iommu->lock, flags); 2321 + spin_lock(&iommu->lock); 2278 2322 context = iommu_context_addr(iommu, bus, devfn, 0); 2279 2323 if (!context) { 2280 - spin_unlock_irqrestore(&iommu->lock, flags); 2324 + spin_unlock(&iommu->lock); 2281 2325 return; 2282 2326 } 2283 2327 ··· 2284 2330 if (hw_pass_through && domain_type_is_si(info->domain)) 2285 2331 did_old = FLPT_DEFAULT_DID; 2286 2332 else 2287 - did_old = info->domain->iommu_did[iommu->seq_id]; 2333 + did_old = domain_id_iommu(info->domain, iommu); 2288 2334 } else { 2289 2335 did_old = context_domain_id(context); 2290 2336 } 2291 2337 2292 2338 context_clear_entry(context); 2293 2339 __iommu_flush_cache(iommu, context, sizeof(*context)); 2294 - spin_unlock_irqrestore(&iommu->lock, flags); 2340 + spin_unlock(&iommu->lock); 2295 2341 iommu->flush.flush_context(iommu, 2296 2342 did_old, 2297 2343 (((u16)bus) << 8) | devfn, ··· 2308 2354 DMA_TLB_DSI_FLUSH); 2309 2355 2310 2356 __iommu_flush_dev_iotlb(info, 0, MAX_AGAW_PFN_WIDTH); 2311 - } 2312 - 2313 - static void domain_remove_dev_info(struct dmar_domain *domain) 2314 - { 2315 - struct device_domain_info *info, *tmp; 2316 - unsigned long flags; 2317 - 2318 - spin_lock_irqsave(&device_domain_lock, flags); 2319 - list_for_each_entry_safe(info, tmp, &domain->devices, link) 2320 - __dmar_remove_one_dev_info(info); 2321 - spin_unlock_irqrestore(&device_domain_lock, flags); 2322 - } 2323 - 2324 - static inline struct device_domain_info * 2325 - dmar_search_domain_by_dev_info(int segment, int bus, int devfn) 2326 - { 2327 - struct device_domain_info *info; 2328 - 2329 - list_for_each_entry(info, &device_domain_list, global) 2330 - if (info->segment == segment && info->bus == bus && 2331 - info->devfn == devfn) 2332 - return info; 2333 - 2334 - return NULL; 2335 2357 } 2336 2358 2337 2359 static int domain_setup_first_level(struct intel_iommu *iommu, ··· 2342 2412 flags |= PASID_FLAG_PAGE_SNOOP; 2343 2413 2344 2414 return intel_pasid_setup_first_level(iommu, dev, (pgd_t *)pgd, pasid, 2345 - domain->iommu_did[iommu->seq_id], 2415 + domain_id_iommu(domain, iommu), 2346 2416 flags); 2347 2417 } 2348 2418 ··· 2429 2499 { 2430 2500 struct device_domain_info *info = dev_iommu_priv_get(dev); 2431 2501 struct intel_iommu *iommu; 2432 - unsigned long flags; 2433 2502 u8 bus, devfn; 2434 2503 int ret; 2435 2504 ··· 2436 2507 if (!iommu) 2437 2508 return -ENODEV; 2438 2509 2439 - spin_lock_irqsave(&device_domain_lock, flags); 2440 - info->domain = domain; 2441 - spin_lock(&iommu->lock); 2442 2510 ret = domain_attach_iommu(domain, iommu); 2443 - spin_unlock(&iommu->lock); 2444 - if (ret) { 2445 - spin_unlock_irqrestore(&device_domain_lock, flags); 2511 + if (ret) 2446 2512 return ret; 2447 - } 2513 + info->domain = domain; 2514 + spin_lock(&domain->lock); 2448 2515 list_add(&info->link, &domain->devices); 2449 - spin_unlock_irqrestore(&device_domain_lock, flags); 2516 + spin_unlock(&domain->lock); 2450 2517 2451 2518 /* PASID table is mandatory for a PCI device in scalable mode. */ 2452 2519 if (sm_supported(iommu) && !dev_is_real_dma_subdevice(dev)) { ··· 2454 2529 } 2455 2530 2456 2531 /* Setup the PASID entry for requests without PASID: */ 2457 - spin_lock_irqsave(&iommu->lock, flags); 2458 2532 if (hw_pass_through && domain_type_is_si(domain)) 2459 2533 ret = intel_pasid_setup_pass_through(iommu, domain, 2460 2534 dev, PASID_RID2PASID); ··· 2463 2539 else 2464 2540 ret = intel_pasid_setup_second_level(iommu, domain, 2465 2541 dev, PASID_RID2PASID); 2466 - spin_unlock_irqrestore(&iommu->lock, flags); 2467 2542 if (ret) { 2468 2543 dev_err(dev, "Setup RID2PASID failed\n"); 2469 2544 dmar_remove_one_dev_info(dev); ··· 2730 2807 struct root_entry *old_rt; 2731 2808 phys_addr_t old_rt_phys; 2732 2809 int ctxt_table_entries; 2733 - unsigned long flags; 2734 2810 u64 rtaddr_reg; 2735 2811 int bus, ret; 2736 2812 bool new_ext, ext; ··· 2772 2850 } 2773 2851 } 2774 2852 2775 - spin_lock_irqsave(&iommu->lock, flags); 2853 + spin_lock(&iommu->lock); 2776 2854 2777 2855 /* Context tables are copied, now write them to the root_entry table */ 2778 2856 for (bus = 0; bus < 256; bus++) { ··· 2791 2869 iommu->root_entry[bus].hi = val; 2792 2870 } 2793 2871 2794 - spin_unlock_irqrestore(&iommu->lock, flags); 2872 + spin_unlock(&iommu->lock); 2795 2873 2796 2874 kfree(ctxt_tbls); 2797 2875 ··· 2890 2968 struct intel_iommu *iommu; 2891 2969 int ret; 2892 2970 2893 - /* 2894 - * for each drhd 2895 - * allocate root 2896 - * initialize and program root entry to not present 2897 - * endfor 2898 - */ 2899 - for_each_drhd_unit(drhd) { 2900 - /* 2901 - * lock not needed as this is only incremented in the single 2902 - * threaded kernel __init code path all other access are read 2903 - * only 2904 - */ 2905 - if (g_num_of_iommus < DMAR_UNITS_SUPPORTED) { 2906 - g_num_of_iommus++; 2907 - continue; 2908 - } 2909 - pr_err_once("Exceeded %d IOMMUs\n", DMAR_UNITS_SUPPORTED); 2910 - } 2911 - 2912 - /* Preallocate enough resources for IOMMU hot-addition */ 2913 - if (g_num_of_iommus < DMAR_UNITS_SUPPORTED) 2914 - g_num_of_iommus = DMAR_UNITS_SUPPORTED; 2915 - 2916 - g_iommus = kcalloc(g_num_of_iommus, sizeof(struct intel_iommu *), 2917 - GFP_KERNEL); 2918 - if (!g_iommus) { 2919 - ret = -ENOMEM; 2920 - goto error; 2921 - } 2922 - 2923 2971 ret = intel_cap_audit(CAP_AUDIT_STATIC_DMAR, NULL); 2924 2972 if (ret) 2925 2973 goto free_iommu; ··· 2911 3019 intel_pasid_max_id = min_t(u32, temp, 2912 3020 intel_pasid_max_id); 2913 3021 } 2914 - 2915 - g_iommus[iommu->seq_id] = iommu; 2916 3022 2917 3023 intel_iommu_init_qi(iommu); 2918 3024 ··· 3037 3147 free_dmar_iommu(iommu); 3038 3148 } 3039 3149 3040 - kfree(g_iommus); 3041 - 3042 - error: 3043 3150 return ret; 3044 3151 } 3045 3152 ··· 3417 3530 int sp, ret; 3418 3531 struct intel_iommu *iommu = dmaru->iommu; 3419 3532 3420 - if (g_iommus[iommu->seq_id]) 3421 - return 0; 3422 - 3423 3533 ret = intel_cap_audit(CAP_AUDIT_HOTPLUG_DMAR, iommu); 3424 3534 if (ret) 3425 3535 goto out; ··· 3440 3556 if (iommu->gcmd & DMA_GCMD_TE) 3441 3557 iommu_disable_translation(iommu); 3442 3558 3443 - g_iommus[iommu->seq_id] = iommu; 3444 3559 ret = iommu_init_domains(iommu); 3445 3560 if (ret == 0) 3446 3561 ret = iommu_alloc_root_entry(iommu); ··· 3905 4022 return 0; 3906 4023 } 3907 4024 4025 + static __init int tboot_force_iommu(void) 4026 + { 4027 + if (!tboot_enabled()) 4028 + return 0; 4029 + 4030 + if (no_iommu || dmar_disabled) 4031 + pr_warn("Forcing Intel-IOMMU to enabled\n"); 4032 + 4033 + dmar_disabled = 0; 4034 + no_iommu = 0; 4035 + 4036 + return 1; 4037 + } 4038 + 3908 4039 int __init intel_iommu_init(void) 3909 4040 { 3910 4041 int ret = -ENODEV; ··· 3989 4092 3990 4093 if (list_empty(&dmar_satc_units)) 3991 4094 pr_info("No SATC found\n"); 3992 - 3993 - if (dmar_map_gfx) 3994 - intel_iommu_gfx_mapped = 1; 3995 4095 3996 4096 init_no_remapping_devices(); 3997 4097 ··· 4075 4181 &domain_context_clear_one_cb, info); 4076 4182 } 4077 4183 4078 - static void __dmar_remove_one_dev_info(struct device_domain_info *info) 4184 + static void dmar_remove_one_dev_info(struct device *dev) 4079 4185 { 4080 - struct dmar_domain *domain; 4081 - struct intel_iommu *iommu; 4082 - unsigned long flags; 4186 + struct device_domain_info *info = dev_iommu_priv_get(dev); 4187 + struct dmar_domain *domain = info->domain; 4188 + struct intel_iommu *iommu = info->iommu; 4083 4189 4084 - assert_spin_locked(&device_domain_lock); 4085 - 4086 - if (WARN_ON(!info)) 4087 - return; 4088 - 4089 - iommu = info->iommu; 4090 - domain = info->domain; 4091 - 4092 - if (info->dev && !dev_is_real_dma_subdevice(info->dev)) { 4190 + if (!dev_is_real_dma_subdevice(info->dev)) { 4093 4191 if (dev_is_pci(info->dev) && sm_supported(iommu)) 4094 4192 intel_pasid_tear_down_entry(iommu, info->dev, 4095 4193 PASID_RID2PASID, false); ··· 4091 4205 intel_pasid_free_table(info->dev); 4092 4206 } 4093 4207 4208 + spin_lock(&domain->lock); 4094 4209 list_del(&info->link); 4210 + spin_unlock(&domain->lock); 4095 4211 4096 - spin_lock_irqsave(&iommu->lock, flags); 4097 4212 domain_detach_iommu(domain, iommu); 4098 - spin_unlock_irqrestore(&iommu->lock, flags); 4099 - } 4100 - 4101 - static void dmar_remove_one_dev_info(struct device *dev) 4102 - { 4103 - struct device_domain_info *info; 4104 - unsigned long flags; 4105 - 4106 - spin_lock_irqsave(&device_domain_lock, flags); 4107 - info = dev_iommu_priv_get(dev); 4108 - if (info) 4109 - __dmar_remove_one_dev_info(info); 4110 - spin_unlock_irqrestore(&device_domain_lock, flags); 4213 + info->domain = NULL; 4111 4214 } 4112 4215 4113 4216 static int md_domain_init(struct dmar_domain *domain, int guest_width) ··· 4341 4466 struct dmar_domain *dmar_domain = to_dmar_domain(domain); 4342 4467 unsigned long iova_pfn = IOVA_PFN(gather->start); 4343 4468 size_t size = gather->end - gather->start; 4469 + struct iommu_domain_info *info; 4344 4470 unsigned long start_pfn; 4345 4471 unsigned long nrpages; 4346 - int iommu_id; 4472 + unsigned long i; 4347 4473 4348 4474 nrpages = aligned_nrpages(gather->start, size); 4349 4475 start_pfn = mm_to_dma_pfn(iova_pfn); 4350 4476 4351 - for_each_domain_iommu(iommu_id, dmar_domain) 4352 - iommu_flush_iotlb_psi(g_iommus[iommu_id], dmar_domain, 4477 + xa_for_each(&dmar_domain->iommu_array, i, info) 4478 + iommu_flush_iotlb_psi(info->iommu, dmar_domain, 4353 4479 start_pfn, nrpages, 4354 4480 list_empty(&gather->freelist), 0); 4355 4481 ··· 4379 4503 struct device_domain_info *info; 4380 4504 bool support = true; 4381 4505 4382 - assert_spin_locked(&device_domain_lock); 4506 + assert_spin_locked(&domain->lock); 4383 4507 list_for_each_entry(info, &domain->devices, link) { 4384 4508 if (!ecap_sc_support(info->iommu->ecap)) { 4385 4509 support = false; ··· 4394 4518 { 4395 4519 struct device_domain_info *info; 4396 4520 4397 - assert_spin_locked(&device_domain_lock); 4398 - 4521 + assert_spin_locked(&domain->lock); 4399 4522 /* 4400 4523 * Second level page table supports per-PTE snoop control. The 4401 4524 * iommu_map() interface will handle this by setting SNP bit. ··· 4412 4537 static bool intel_iommu_enforce_cache_coherency(struct iommu_domain *domain) 4413 4538 { 4414 4539 struct dmar_domain *dmar_domain = to_dmar_domain(domain); 4415 - unsigned long flags; 4416 4540 4417 4541 if (dmar_domain->force_snooping) 4418 4542 return true; 4419 4543 4420 - spin_lock_irqsave(&device_domain_lock, flags); 4544 + spin_lock(&dmar_domain->lock); 4421 4545 if (!domain_support_force_snooping(dmar_domain)) { 4422 - spin_unlock_irqrestore(&device_domain_lock, flags); 4546 + spin_unlock(&dmar_domain->lock); 4423 4547 return false; 4424 4548 } 4425 4549 4426 4550 domain_set_force_snooping(dmar_domain); 4427 4551 dmar_domain->force_snooping = true; 4428 - spin_unlock_irqrestore(&device_domain_lock, flags); 4552 + spin_unlock(&dmar_domain->lock); 4429 4553 4430 4554 return true; 4431 4555 } ··· 4446 4572 struct pci_dev *pdev = dev_is_pci(dev) ? to_pci_dev(dev) : NULL; 4447 4573 struct device_domain_info *info; 4448 4574 struct intel_iommu *iommu; 4449 - unsigned long flags; 4450 4575 u8 bus, devfn; 4451 4576 4452 4577 iommu = device_to_iommu(dev, &bus, &devfn); ··· 4488 4615 } 4489 4616 } 4490 4617 4491 - spin_lock_irqsave(&device_domain_lock, flags); 4492 - list_add(&info->global, &device_domain_list); 4493 4618 dev_iommu_priv_set(dev, info); 4494 - spin_unlock_irqrestore(&device_domain_lock, flags); 4495 4619 4496 4620 return &iommu->iommu; 4497 4621 } ··· 4496 4626 static void intel_iommu_release_device(struct device *dev) 4497 4627 { 4498 4628 struct device_domain_info *info = dev_iommu_priv_get(dev); 4499 - unsigned long flags; 4500 4629 4501 4630 dmar_remove_one_dev_info(dev); 4502 - 4503 - spin_lock_irqsave(&device_domain_lock, flags); 4504 4631 dev_iommu_priv_set(dev, NULL); 4505 - list_del(&info->global); 4506 - spin_unlock_irqrestore(&device_domain_lock, flags); 4507 - 4508 4632 kfree(info); 4509 4633 set_dma_ops(dev, NULL); 4510 4634 } ··· 4571 4707 struct device_domain_info *info = dev_iommu_priv_get(dev); 4572 4708 struct context_entry *context; 4573 4709 struct dmar_domain *domain; 4574 - unsigned long flags; 4575 4710 u64 ctx_lo; 4576 4711 int ret; 4577 4712 ··· 4578 4715 if (!domain) 4579 4716 return -EINVAL; 4580 4717 4581 - spin_lock_irqsave(&device_domain_lock, flags); 4582 4718 spin_lock(&iommu->lock); 4583 - 4584 4719 ret = -EINVAL; 4585 4720 if (!info->pasid_supported) 4586 4721 goto out; ··· 4594 4733 context[0].lo = ctx_lo; 4595 4734 wmb(); 4596 4735 iommu->flush.flush_context(iommu, 4597 - domain->iommu_did[iommu->seq_id], 4736 + domain_id_iommu(domain, iommu), 4598 4737 PCI_DEVID(info->bus, info->devfn), 4599 4738 DMA_CCMD_MASK_NOBIT, 4600 4739 DMA_CCMD_DEVICE_INVL); ··· 4608 4747 4609 4748 out: 4610 4749 spin_unlock(&iommu->lock); 4611 - spin_unlock_irqrestore(&device_domain_lock, flags); 4612 4750 4613 4751 return ret; 4614 4752 } ··· 4731 4871 struct dmar_domain *dmar_domain = to_dmar_domain(domain); 4732 4872 unsigned long pages = aligned_nrpages(iova, size); 4733 4873 unsigned long pfn = iova >> VTD_PAGE_SHIFT; 4734 - struct intel_iommu *iommu; 4735 - int iommu_id; 4874 + struct iommu_domain_info *info; 4875 + unsigned long i; 4736 4876 4737 - for_each_domain_iommu(iommu_id, dmar_domain) { 4738 - iommu = g_iommus[iommu_id]; 4739 - __mapping_notify_one(iommu, dmar_domain, pfn, pages); 4740 - } 4877 + xa_for_each(&dmar_domain->iommu_array, i, info) 4878 + __mapping_notify_one(info->iommu, dmar_domain, pfn, pages); 4741 4879 } 4742 4880 4743 4881 const struct iommu_ops intel_iommu_ops = { ··· 4745 4887 .probe_finalize = intel_iommu_probe_finalize, 4746 4888 .release_device = intel_iommu_release_device, 4747 4889 .get_resv_regions = intel_iommu_get_resv_regions, 4748 - .put_resv_regions = generic_iommu_put_resv_regions, 4749 4890 .device_group = intel_iommu_device_group, 4750 4891 .dev_enable_feat = intel_iommu_dev_enable_feat, 4751 4892 .dev_disable_feat = intel_iommu_dev_disable_feat,
+1 -1
drivers/iommu/intel/irq_remapping.c
··· 10 10 #include <linux/hpet.h> 11 11 #include <linux/pci.h> 12 12 #include <linux/irq.h> 13 - #include <linux/intel-iommu.h> 14 13 #include <linux/acpi.h> 15 14 #include <linux/irqdomain.h> 16 15 #include <linux/crash_dump.h> ··· 20 21 #include <asm/irq_remapping.h> 21 22 #include <asm/pci-direct.h> 22 23 24 + #include "iommu.h" 23 25 #include "../irq_remapping.h" 24 26 #include "cap_audit.h" 25 27
+58 -51
drivers/iommu/intel/pasid.c
··· 12 12 #include <linux/bitops.h> 13 13 #include <linux/cpufeature.h> 14 14 #include <linux/dmar.h> 15 - #include <linux/intel-iommu.h> 16 15 #include <linux/iommu.h> 17 16 #include <linux/memory.h> 18 17 #include <linux/pci.h> 19 18 #include <linux/pci-ats.h> 20 19 #include <linux/spinlock.h> 21 20 21 + #include "iommu.h" 22 22 #include "pasid.h" 23 23 24 24 /* ··· 450 450 struct pasid_entry *pte; 451 451 u16 did, pgtt; 452 452 453 + spin_lock(&iommu->lock); 453 454 pte = intel_pasid_get_entry(dev, pasid); 454 - if (WARN_ON(!pte)) 455 + if (WARN_ON(!pte) || !pasid_pte_is_present(pte)) { 456 + spin_unlock(&iommu->lock); 455 457 return; 456 - 457 - if (!pasid_pte_is_present(pte)) 458 - return; 458 + } 459 459 460 460 did = pasid_get_domain_id(pte); 461 461 pgtt = pasid_pte_get_pgtt(pte); 462 - 463 462 intel_pasid_clear_entry(dev, pasid, fault_ignore); 463 + spin_unlock(&iommu->lock); 464 464 465 465 if (!ecap_coherent(iommu->ecap)) 466 466 clflush_cache_range(pte, sizeof(*pte)); ··· 496 496 } 497 497 } 498 498 499 - static inline int pasid_enable_wpe(struct pasid_entry *pte) 500 - { 501 - #ifdef CONFIG_X86 502 - unsigned long cr0 = read_cr0(); 503 - 504 - /* CR0.WP is normally set but just to be sure */ 505 - if (unlikely(!(cr0 & X86_CR0_WP))) { 506 - pr_err_ratelimited("No CPU write protect!\n"); 507 - return -EINVAL; 508 - } 509 - #endif 510 - pasid_set_wpe(pte); 511 - 512 - return 0; 513 - }; 514 - 515 499 /* 516 500 * Set up the scalable mode pasid table entry for first only 517 501 * translation type. ··· 512 528 return -EINVAL; 513 529 } 514 530 515 - pte = intel_pasid_get_entry(dev, pasid); 516 - if (WARN_ON(!pte)) 517 - return -EINVAL; 531 + if (flags & PASID_FLAG_SUPERVISOR_MODE) { 532 + #ifdef CONFIG_X86 533 + unsigned long cr0 = read_cr0(); 518 534 519 - /* Caller must ensure PASID entry is not in use. */ 520 - if (pasid_pte_is_present(pte)) 535 + /* CR0.WP is normally set but just to be sure */ 536 + if (unlikely(!(cr0 & X86_CR0_WP))) { 537 + pr_err("No CPU write protect!\n"); 538 + return -EINVAL; 539 + } 540 + #endif 541 + if (!ecap_srs(iommu->ecap)) { 542 + pr_err("No supervisor request support on %s\n", 543 + iommu->name); 544 + return -EINVAL; 545 + } 546 + } 547 + 548 + if ((flags & PASID_FLAG_FL5LP) && !cap_5lp_support(iommu->cap)) { 549 + pr_err("No 5-level paging support for first-level on %s\n", 550 + iommu->name); 551 + return -EINVAL; 552 + } 553 + 554 + spin_lock(&iommu->lock); 555 + pte = intel_pasid_get_entry(dev, pasid); 556 + if (!pte) { 557 + spin_unlock(&iommu->lock); 558 + return -ENODEV; 559 + } 560 + 561 + if (pasid_pte_is_present(pte)) { 562 + spin_unlock(&iommu->lock); 521 563 return -EBUSY; 564 + } 522 565 523 566 pasid_clear_entry(pte); 524 567 525 568 /* Setup the first level page table pointer: */ 526 569 pasid_set_flptr(pte, (u64)__pa(pgd)); 527 570 if (flags & PASID_FLAG_SUPERVISOR_MODE) { 528 - if (!ecap_srs(iommu->ecap)) { 529 - pr_err("No supervisor request support on %s\n", 530 - iommu->name); 531 - return -EINVAL; 532 - } 533 571 pasid_set_sre(pte); 534 - if (pasid_enable_wpe(pte)) 535 - return -EINVAL; 536 - 572 + pasid_set_wpe(pte); 537 573 } 538 574 539 - if (flags & PASID_FLAG_FL5LP) { 540 - if (cap_5lp_support(iommu->cap)) { 541 - pasid_set_flpm(pte, 1); 542 - } else { 543 - pr_err("No 5-level paging support for first-level\n"); 544 - pasid_clear_entry(pte); 545 - return -EINVAL; 546 - } 547 - } 575 + if (flags & PASID_FLAG_FL5LP) 576 + pasid_set_flpm(pte, 1); 548 577 549 578 if (flags & PASID_FLAG_PAGE_SNOOP) 550 579 pasid_set_pgsnp(pte); ··· 569 572 /* Setup Present and PASID Granular Transfer Type: */ 570 573 pasid_set_translation_type(pte, PASID_ENTRY_PGTT_FL_ONLY); 571 574 pasid_set_present(pte); 575 + spin_unlock(&iommu->lock); 576 + 572 577 pasid_flush_caches(iommu, pte, pasid, did); 573 578 574 579 return 0; ··· 626 627 } 627 628 628 629 pgd_val = virt_to_phys(pgd); 629 - did = domain->iommu_did[iommu->seq_id]; 630 + did = domain_id_iommu(domain, iommu); 630 631 632 + spin_lock(&iommu->lock); 631 633 pte = intel_pasid_get_entry(dev, pasid); 632 634 if (!pte) { 633 - dev_err(dev, "Failed to get pasid entry of PASID %d\n", pasid); 635 + spin_unlock(&iommu->lock); 634 636 return -ENODEV; 635 637 } 636 638 637 - /* Caller must ensure PASID entry is not in use. */ 638 - if (pasid_pte_is_present(pte)) 639 + if (pasid_pte_is_present(pte)) { 640 + spin_unlock(&iommu->lock); 639 641 return -EBUSY; 642 + } 640 643 641 644 pasid_clear_entry(pte); 642 645 pasid_set_domain_id(pte, did); ··· 655 654 if (pasid != PASID_RID2PASID) 656 655 pasid_set_sre(pte); 657 656 pasid_set_present(pte); 657 + spin_unlock(&iommu->lock); 658 + 658 659 pasid_flush_caches(iommu, pte, pasid, did); 659 660 660 661 return 0; ··· 672 669 u16 did = FLPT_DEFAULT_DID; 673 670 struct pasid_entry *pte; 674 671 672 + spin_lock(&iommu->lock); 675 673 pte = intel_pasid_get_entry(dev, pasid); 676 674 if (!pte) { 677 - dev_err(dev, "Failed to get pasid entry of PASID %d\n", pasid); 675 + spin_unlock(&iommu->lock); 678 676 return -ENODEV; 679 677 } 680 678 681 - /* Caller must ensure PASID entry is not in use. */ 682 - if (pasid_pte_is_present(pte)) 679 + if (pasid_pte_is_present(pte)) { 680 + spin_unlock(&iommu->lock); 683 681 return -EBUSY; 682 + } 684 683 685 684 pasid_clear_entry(pte); 686 685 pasid_set_domain_id(pte, did); ··· 697 692 */ 698 693 pasid_set_sre(pte); 699 694 pasid_set_present(pte); 695 + spin_unlock(&iommu->lock); 696 + 700 697 pasid_flush_caches(iommu, pte, pasid, did); 701 698 702 699 return 0;
+1
drivers/iommu/intel/pasid.h
··· 39 39 * only and pass-through transfer modes. 40 40 */ 41 41 #define FLPT_DEFAULT_DID 1 42 + #define NUM_RESERVED_DID 2 42 43 43 44 /* 44 45 * The SUPERVISOR_MODE flag indicates a first level translation which
+1 -1
drivers/iommu/intel/perf.c
··· 9 9 */ 10 10 11 11 #include <linux/spinlock.h> 12 - #include <linux/intel-iommu.h> 13 12 13 + #include "iommu.h" 14 14 #include "perf.h" 15 15 16 16 static DEFINE_SPINLOCK(latency_lock);
+4 -7
drivers/iommu/intel/svm.c
··· 5 5 * Authors: David Woodhouse <dwmw2@infradead.org> 6 6 */ 7 7 8 - #include <linux/intel-iommu.h> 9 8 #include <linux/mmu_notifier.h> 10 9 #include <linux/sched.h> 11 10 #include <linux/sched/mm.h> ··· 20 21 #include <linux/ioasid.h> 21 22 #include <asm/page.h> 22 23 #include <asm/fpu/api.h> 23 - #include <trace/events/intel_iommu.h> 24 24 25 + #include "iommu.h" 25 26 #include "pasid.h" 26 27 #include "perf.h" 27 28 #include "../iommu-sva-lib.h" 29 + #include "trace.h" 28 30 29 31 static irqreturn_t prq_event_thread(int irq, void *d); 30 32 static void intel_svm_drain_prq(struct device *dev, u32 pasid); ··· 328 328 unsigned int flags) 329 329 { 330 330 struct device_domain_info *info = dev_iommu_priv_get(dev); 331 - unsigned long iflags, sflags; 332 331 struct intel_svm_dev *sdev; 333 332 struct intel_svm *svm; 333 + unsigned long sflags; 334 334 int ret = 0; 335 335 336 336 svm = pasid_private_find(mm->pasid); ··· 394 394 sflags = (flags & SVM_FLAG_SUPERVISOR_MODE) ? 395 395 PASID_FLAG_SUPERVISOR_MODE : 0; 396 396 sflags |= cpu_feature_enabled(X86_FEATURE_LA57) ? PASID_FLAG_FL5LP : 0; 397 - spin_lock_irqsave(&iommu->lock, iflags); 398 397 ret = intel_pasid_setup_first_level(iommu, dev, mm->pgd, mm->pasid, 399 398 FLPT_DEFAULT_DID, sflags); 400 - spin_unlock_irqrestore(&iommu->lock, iflags); 401 - 402 399 if (ret) 403 400 goto free_sdev; 404 401 ··· 541 544 domain = info->domain; 542 545 pdev = to_pci_dev(dev); 543 546 sid = PCI_DEVID(info->bus, info->devfn); 544 - did = domain->iommu_did[iommu->seq_id]; 547 + did = domain_id_iommu(domain, iommu); 545 548 qdep = pci_ats_queue_depth(pdev); 546 549 547 550 /*
+1 -1
drivers/iommu/intel/trace.c
··· 11 11 #include <linux/types.h> 12 12 13 13 #define CREATE_TRACE_POINTS 14 - #include <trace/events/intel_iommu.h> 14 + #include "trace.h"
+56 -19
drivers/iommu/io-pgtable-arm-v7s.c
··· 182 182 (cfg->quirks & IO_PGTABLE_QUIRK_ARM_MTK_EXT); 183 183 } 184 184 185 - static arm_v7s_iopte paddr_to_iopte(phys_addr_t paddr, int lvl, 186 - struct io_pgtable_cfg *cfg) 185 + static arm_v7s_iopte to_mtk_iopte(phys_addr_t paddr, arm_v7s_iopte pte) 187 186 { 188 - arm_v7s_iopte pte = paddr & ARM_V7S_LVL_MASK(lvl); 189 - 190 - if (!arm_v7s_is_mtk_enabled(cfg)) 191 - return pte; 192 - 193 187 if (paddr & BIT_ULL(32)) 194 188 pte |= ARM_V7S_ATTR_MTK_PA_BIT32; 195 189 if (paddr & BIT_ULL(33)) 196 190 pte |= ARM_V7S_ATTR_MTK_PA_BIT33; 197 191 if (paddr & BIT_ULL(34)) 198 192 pte |= ARM_V7S_ATTR_MTK_PA_BIT34; 193 + return pte; 194 + } 195 + 196 + static arm_v7s_iopte paddr_to_iopte(phys_addr_t paddr, int lvl, 197 + struct io_pgtable_cfg *cfg) 198 + { 199 + arm_v7s_iopte pte = paddr & ARM_V7S_LVL_MASK(lvl); 200 + 201 + if (arm_v7s_is_mtk_enabled(cfg)) 202 + return to_mtk_iopte(paddr, pte); 203 + 199 204 return pte; 200 205 } 201 206 ··· 245 240 dma_addr_t dma; 246 241 size_t size = ARM_V7S_TABLE_SIZE(lvl, cfg); 247 242 void *table = NULL; 243 + gfp_t gfp_l1; 244 + 245 + /* 246 + * ARM_MTK_TTBR_EXT extend the translation table base support larger 247 + * memory address. 248 + */ 249 + gfp_l1 = cfg->quirks & IO_PGTABLE_QUIRK_ARM_MTK_TTBR_EXT ? 250 + GFP_KERNEL : ARM_V7S_TABLE_GFP_DMA; 248 251 249 252 if (lvl == 1) 250 - table = (void *)__get_free_pages( 251 - __GFP_ZERO | ARM_V7S_TABLE_GFP_DMA, get_order(size)); 253 + table = (void *)__get_free_pages(gfp_l1 | __GFP_ZERO, get_order(size)); 252 254 else if (lvl == 2) 253 255 table = kmem_cache_zalloc(data->l2_tables, gfp); 254 256 ··· 263 251 return NULL; 264 252 265 253 phys = virt_to_phys(table); 266 - if (phys != (arm_v7s_iopte)phys) { 254 + if (cfg->quirks & IO_PGTABLE_QUIRK_ARM_MTK_TTBR_EXT ? 255 + phys >= (1ULL << cfg->oas) : phys != (arm_v7s_iopte)phys) { 267 256 /* Doesn't fit in PTE */ 268 257 dev_err(dev, "Page table does not fit in PTE: %pa", &phys); 269 258 goto out_free; ··· 470 457 arm_v7s_iopte curr, 471 458 struct io_pgtable_cfg *cfg) 472 459 { 460 + phys_addr_t phys = virt_to_phys(table); 473 461 arm_v7s_iopte old, new; 474 462 475 - new = virt_to_phys(table) | ARM_V7S_PTE_TYPE_TABLE; 463 + new = phys | ARM_V7S_PTE_TYPE_TABLE; 464 + 465 + if (cfg->quirks & IO_PGTABLE_QUIRK_ARM_MTK_TTBR_EXT) 466 + new = to_mtk_iopte(phys, new); 467 + 476 468 if (cfg->quirks & IO_PGTABLE_QUIRK_ARM_NS) 477 469 new |= ARM_V7S_ATTR_NS_TABLE; 478 470 ··· 797 779 void *cookie) 798 780 { 799 781 struct arm_v7s_io_pgtable *data; 782 + slab_flags_t slab_flag; 783 + phys_addr_t paddr; 800 784 801 785 if (cfg->ias > (arm_v7s_is_mtk_enabled(cfg) ? 34 : ARM_V7S_ADDR_BITS)) 802 786 return NULL; ··· 808 788 809 789 if (cfg->quirks & ~(IO_PGTABLE_QUIRK_ARM_NS | 810 790 IO_PGTABLE_QUIRK_NO_PERMS | 811 - IO_PGTABLE_QUIRK_ARM_MTK_EXT)) 791 + IO_PGTABLE_QUIRK_ARM_MTK_EXT | 792 + IO_PGTABLE_QUIRK_ARM_MTK_TTBR_EXT)) 812 793 return NULL; 813 794 814 795 /* If ARM_MTK_4GB is enabled, the NO_PERMS is also expected. */ ··· 817 796 !(cfg->quirks & IO_PGTABLE_QUIRK_NO_PERMS)) 818 797 return NULL; 819 798 799 + if ((cfg->quirks & IO_PGTABLE_QUIRK_ARM_MTK_TTBR_EXT) && 800 + !arm_v7s_is_mtk_enabled(cfg)) 801 + return NULL; 802 + 820 803 data = kmalloc(sizeof(*data), GFP_KERNEL); 821 804 if (!data) 822 805 return NULL; 823 806 824 807 spin_lock_init(&data->split_lock); 808 + 809 + /* 810 + * ARM_MTK_TTBR_EXT extend the translation table base support larger 811 + * memory address. 812 + */ 813 + slab_flag = cfg->quirks & IO_PGTABLE_QUIRK_ARM_MTK_TTBR_EXT ? 814 + 0 : ARM_V7S_TABLE_SLAB_FLAGS; 815 + 825 816 data->l2_tables = kmem_cache_create("io-pgtable_armv7s_l2", 826 817 ARM_V7S_TABLE_SIZE(2, cfg), 827 818 ARM_V7S_TABLE_SIZE(2, cfg), 828 - ARM_V7S_TABLE_SLAB_FLAGS, NULL); 819 + slab_flag, NULL); 829 820 if (!data->l2_tables) 830 821 goto out_free_data; 831 822 ··· 883 850 wmb(); 884 851 885 852 /* TTBR */ 886 - cfg->arm_v7s_cfg.ttbr = virt_to_phys(data->pgd) | ARM_V7S_TTBR_S | 887 - (cfg->coherent_walk ? (ARM_V7S_TTBR_NOS | 888 - ARM_V7S_TTBR_IRGN_ATTR(ARM_V7S_RGN_WBWA) | 889 - ARM_V7S_TTBR_ORGN_ATTR(ARM_V7S_RGN_WBWA)) : 890 - (ARM_V7S_TTBR_IRGN_ATTR(ARM_V7S_RGN_NC) | 891 - ARM_V7S_TTBR_ORGN_ATTR(ARM_V7S_RGN_NC))); 853 + paddr = virt_to_phys(data->pgd); 854 + if (arm_v7s_is_mtk_enabled(cfg)) 855 + cfg->arm_v7s_cfg.ttbr = paddr | upper_32_bits(paddr); 856 + else 857 + cfg->arm_v7s_cfg.ttbr = paddr | ARM_V7S_TTBR_S | 858 + (cfg->coherent_walk ? (ARM_V7S_TTBR_NOS | 859 + ARM_V7S_TTBR_IRGN_ATTR(ARM_V7S_RGN_WBWA) | 860 + ARM_V7S_TTBR_ORGN_ATTR(ARM_V7S_RGN_WBWA)) : 861 + (ARM_V7S_TTBR_IRGN_ATTR(ARM_V7S_RGN_NC) | 862 + ARM_V7S_TTBR_ORGN_ATTR(ARM_V7S_RGN_NC))); 892 863 return &data->iop; 893 864 894 865 out_free_data:
+19 -36
drivers/iommu/iommu.c
··· 259 259 return 0; 260 260 261 261 out_release: 262 - ops->release_device(dev); 262 + if (ops->release_device) 263 + ops->release_device(dev); 263 264 264 265 out_module_put: 265 266 module_put(ops->owner); ··· 273 272 274 273 int iommu_probe_device(struct device *dev) 275 274 { 276 - const struct iommu_ops *ops = dev->bus->iommu_ops; 275 + const struct iommu_ops *ops; 277 276 struct iommu_group *group; 278 277 int ret; 279 278 ··· 314 313 mutex_unlock(&group->mutex); 315 314 iommu_group_put(group); 316 315 316 + ops = dev_iommu_ops(dev); 317 317 if (ops->probe_finalize) 318 318 ops->probe_finalize(dev); 319 319 ··· 338 336 iommu_device_unlink(dev->iommu->iommu_dev, dev); 339 337 340 338 ops = dev_iommu_ops(dev); 341 - ops->release_device(dev); 339 + if (ops->release_device) 340 + ops->release_device(dev); 342 341 343 342 iommu_group_remove_device(dev); 344 343 module_put(ops->owner); ··· 603 600 if (group->iommu_data_release) 604 601 group->iommu_data_release(group->iommu_data); 605 602 606 - ida_simple_remove(&iommu_group_ida, group->id); 603 + ida_free(&iommu_group_ida, group->id); 607 604 608 605 if (group->default_domain) 609 606 iommu_domain_free(group->default_domain); ··· 644 641 INIT_LIST_HEAD(&group->devices); 645 642 INIT_LIST_HEAD(&group->entry); 646 643 647 - ret = ida_simple_get(&iommu_group_ida, 0, 0, GFP_KERNEL); 644 + ret = ida_alloc(&iommu_group_ida, GFP_KERNEL); 648 645 if (ret < 0) { 649 646 kfree(group); 650 647 return ERR_PTR(ret); ··· 654 651 ret = kobject_init_and_add(&group->kobj, &iommu_group_ktype, 655 652 NULL, "%d", group->id); 656 653 if (ret) { 657 - ida_simple_remove(&iommu_group_ida, group->id); 654 + ida_free(&iommu_group_ida, group->id); 658 655 kobject_put(&group->kobj); 659 656 return ERR_PTR(ret); 660 657 } ··· 2579 2576 ops->get_resv_regions(dev, list); 2580 2577 } 2581 2578 2582 - void iommu_put_resv_regions(struct device *dev, struct list_head *list) 2583 - { 2584 - const struct iommu_ops *ops = dev_iommu_ops(dev); 2585 - 2586 - if (ops->put_resv_regions) 2587 - ops->put_resv_regions(dev, list); 2588 - } 2589 - 2590 2579 /** 2591 - * generic_iommu_put_resv_regions - Reserved region driver helper 2580 + * iommu_put_resv_regions - release resered regions 2592 2581 * @dev: device for which to free reserved regions 2593 2582 * @list: reserved region list for device 2594 2583 * 2595 - * IOMMU drivers can use this to implement their .put_resv_regions() callback 2596 - * for simple reservations. Memory allocated for each reserved region will be 2597 - * freed. If an IOMMU driver allocates additional resources per region, it is 2598 - * going to have to implement a custom callback. 2584 + * This releases a reserved region list acquired by iommu_get_resv_regions(). 2599 2585 */ 2600 - void generic_iommu_put_resv_regions(struct device *dev, struct list_head *list) 2586 + void iommu_put_resv_regions(struct device *dev, struct list_head *list) 2601 2587 { 2602 2588 struct iommu_resv_region *entry, *next; 2603 2589 2604 - list_for_each_entry_safe(entry, next, list, list) 2605 - kfree(entry); 2590 + list_for_each_entry_safe(entry, next, list, list) { 2591 + if (entry->free) 2592 + entry->free(dev, entry); 2593 + else 2594 + kfree(entry); 2595 + } 2606 2596 } 2607 - EXPORT_SYMBOL(generic_iommu_put_resv_regions); 2597 + EXPORT_SYMBOL(iommu_put_resv_regions); 2608 2598 2609 2599 struct iommu_resv_region *iommu_alloc_resv_region(phys_addr_t start, 2610 2600 size_t length, int prot, ··· 2746 2750 return -EBUSY; 2747 2751 } 2748 2752 EXPORT_SYMBOL_GPL(iommu_dev_disable_feature); 2749 - 2750 - bool iommu_dev_feature_enabled(struct device *dev, enum iommu_dev_features feat) 2751 - { 2752 - if (dev->iommu && dev->iommu->iommu_dev) { 2753 - const struct iommu_ops *ops = dev->iommu->iommu_dev->ops; 2754 - 2755 - if (ops->dev_feat_enabled) 2756 - return ops->dev_feat_enabled(dev, feat); 2757 - } 2758 - 2759 - return false; 2760 - } 2761 - EXPORT_SYMBOL_GPL(iommu_dev_feature_enabled); 2762 2753 2763 2754 /** 2764 2755 * iommu_sva_bind_device() - Bind a process address space to a device
+6 -1
drivers/iommu/iova.c
··· 614 614 * dynamic size tuning described in the paper. 615 615 */ 616 616 617 - #define IOVA_MAG_SIZE 128 617 + /* 618 + * As kmalloc's buffer size is fixed to power of 2, 127 is chosen to 619 + * assure size of 'iova_magazine' to be 1024 bytes, so that no memory 620 + * will be wasted. 621 + */ 622 + #define IOVA_MAG_SIZE 127 618 623 #define MAX_GLOBAL_MAGS 32 /* magazines per bin */ 619 624 620 625 struct iova_magazine {
+1 -6
drivers/iommu/msm_iommu.c
··· 394 394 return &iommu->iommu; 395 395 } 396 396 397 - static void msm_iommu_release_device(struct device *dev) 398 - { 399 - } 400 - 401 397 static int msm_iommu_attach_dev(struct iommu_domain *domain, struct device *dev) 402 398 { 403 399 int ret = 0; ··· 599 603 600 604 for (sid = 0; sid < master->num_mids; sid++) 601 605 if (master->mids[sid] == spec->args[0]) { 602 - dev_warn(dev, "Stream ID 0x%hx repeated; ignoring\n", 606 + dev_warn(dev, "Stream ID 0x%x repeated; ignoring\n", 603 607 sid); 604 608 return 0; 605 609 } ··· 673 677 static struct iommu_ops msm_iommu_ops = { 674 678 .domain_alloc = msm_iommu_domain_alloc, 675 679 .probe_device = msm_iommu_probe_device, 676 - .release_device = msm_iommu_release_device, 677 680 .device_group = generic_device_group, 678 681 .pgsize_bitmap = MSM_IOMMU_PGSIZES, 679 682 .of_xlate = qcom_iommu_of_xlate,
+37 -34
drivers/iommu/mtk_iommu.c
··· 34 34 #include <dt-bindings/memory/mtk-memory-port.h> 35 35 36 36 #define REG_MMU_PT_BASE_ADDR 0x000 37 - #define MMU_PT_ADDR_MASK GENMASK(31, 7) 38 37 39 38 #define REG_MMU_INVALIDATE 0x020 40 39 #define F_ALL_INVLD 0x2 ··· 137 138 /* PM and clock always on. e.g. infra iommu */ 138 139 #define PM_CLK_AO BIT(15) 139 140 #define IFA_IOMMU_PCIE_SUPPORT BIT(16) 141 + #define PGTABLE_PA_35_EN BIT(17) 140 142 141 143 #define MTK_IOMMU_HAS_FLAG_MASK(pdata, _x, mask) \ 142 144 ((((pdata)->flags) & (mask)) == (_x)) ··· 596 596 .iommu_dev = data->dev, 597 597 }; 598 598 599 + if (MTK_IOMMU_HAS_FLAG(data->plat_data, PGTABLE_PA_35_EN)) 600 + dom->cfg.quirks |= IO_PGTABLE_QUIRK_ARM_MTK_TTBR_EXT; 601 + 599 602 if (MTK_IOMMU_HAS_FLAG(data->plat_data, HAS_4GB_MODE)) 600 603 dom->cfg.oas = data->enable_4GB ? 33 : 32; 601 604 else ··· 687 684 goto err_unlock; 688 685 } 689 686 bank->m4u_dom = dom; 690 - writel(dom->cfg.arm_v7s_cfg.ttbr & MMU_PT_ADDR_MASK, 691 - bank->base + REG_MMU_PT_BASE_ADDR); 687 + writel(dom->cfg.arm_v7s_cfg.ttbr, bank->base + REG_MMU_PT_BASE_ADDR); 692 688 693 689 pm_runtime_put(m4udev); 694 690 } ··· 821 819 struct device *larbdev; 822 820 unsigned int larbid; 823 821 824 - if (!fwspec || fwspec->ops != &mtk_iommu_ops) 825 - return; 826 - 827 822 data = dev_iommu_priv_get(dev); 828 823 if (MTK_IOMMU_IS_TYPE(data->plat_data, MTK_IOMMU_TYPE_MM)) { 829 824 larbid = MTK_M4U_TO_LARB(fwspec->ids[0]); 830 825 larbdev = data->larb_imu[larbid].dev; 831 826 device_link_remove(dev, larbdev); 832 827 } 833 - 834 - iommu_fwspec_free(dev); 835 828 } 836 829 837 830 static int mtk_iommu_get_group_id(struct device *dev, const struct mtk_iommu_plat_data *plat_data) ··· 930 933 .device_group = mtk_iommu_device_group, 931 934 .of_xlate = mtk_iommu_of_xlate, 932 935 .get_resv_regions = mtk_iommu_get_resv_regions, 933 - .put_resv_regions = generic_iommu_put_resv_regions, 934 936 .pgsize_bitmap = SZ_4K | SZ_64K | SZ_1M | SZ_16M, 935 937 .owner = THIS_MODULE, 936 938 .default_domain_ops = &(const struct iommu_domain_ops) { ··· 1136 1140 data->protect_base = ALIGN(virt_to_phys(protect), MTK_PROTECT_PA_ALIGN); 1137 1141 1138 1142 if (MTK_IOMMU_HAS_FLAG(data->plat_data, HAS_4GB_MODE)) { 1139 - switch (data->plat_data->m4u_plat) { 1140 - case M4U_MT2712: 1141 - p = "mediatek,mt2712-infracfg"; 1142 - break; 1143 - case M4U_MT8173: 1144 - p = "mediatek,mt8173-infracfg"; 1145 - break; 1146 - default: 1147 - p = NULL; 1143 + infracfg = syscon_regmap_lookup_by_phandle(dev->of_node, "mediatek,infracfg"); 1144 + if (IS_ERR(infracfg)) { 1145 + /* 1146 + * Legacy devicetrees will not specify a phandle to 1147 + * mediatek,infracfg: in that case, we use the older 1148 + * way to retrieve a syscon to infra. 1149 + * 1150 + * This is for retrocompatibility purposes only, hence 1151 + * no more compatibles shall be added to this. 1152 + */ 1153 + switch (data->plat_data->m4u_plat) { 1154 + case M4U_MT2712: 1155 + p = "mediatek,mt2712-infracfg"; 1156 + break; 1157 + case M4U_MT8173: 1158 + p = "mediatek,mt8173-infracfg"; 1159 + break; 1160 + default: 1161 + p = NULL; 1162 + } 1163 + 1164 + infracfg = syscon_regmap_lookup_by_compatible(p); 1165 + if (IS_ERR(infracfg)) 1166 + return PTR_ERR(infracfg); 1148 1167 } 1149 - 1150 - infracfg = syscon_regmap_lookup_by_compatible(p); 1151 - 1152 - if (IS_ERR(infracfg)) 1153 - return PTR_ERR(infracfg); 1154 1168 1155 1169 ret = regmap_read(infracfg, REG_INFRA_MISC, &val); 1156 1170 if (ret) ··· 1210 1204 if (MTK_IOMMU_IS_TYPE(data->plat_data, MTK_IOMMU_TYPE_MM)) { 1211 1205 ret = mtk_iommu_mm_dts_parse(dev, &match, data); 1212 1206 if (ret) { 1213 - dev_err(dev, "mm dts parse fail(%d).", ret); 1207 + dev_err_probe(dev, ret, "mm dts parse fail\n"); 1214 1208 goto out_runtime_disable; 1215 1209 } 1216 - } else if (MTK_IOMMU_IS_TYPE(data->plat_data, MTK_IOMMU_TYPE_INFRA) && 1217 - data->plat_data->pericfg_comp_str) { 1218 - infracfg = syscon_regmap_lookup_by_compatible(data->plat_data->pericfg_comp_str); 1219 - if (IS_ERR(infracfg)) { 1220 - ret = PTR_ERR(infracfg); 1210 + } else if (MTK_IOMMU_IS_TYPE(data->plat_data, MTK_IOMMU_TYPE_INFRA)) { 1211 + p = data->plat_data->pericfg_comp_str; 1212 + data->pericfg = syscon_regmap_lookup_by_compatible(p); 1213 + if (IS_ERR(data->pericfg)) { 1214 + ret = PTR_ERR(data->pericfg); 1221 1215 goto out_runtime_disable; 1222 1216 } 1223 - 1224 - data->pericfg = infracfg; 1225 1217 } 1226 1218 1227 1219 platform_set_drvdata(pdev, data); ··· 1370 1366 writel_relaxed(reg->int_control[i], base + REG_MMU_INT_CONTROL0); 1371 1367 writel_relaxed(reg->int_main_control[i], base + REG_MMU_INT_MAIN_CONTROL); 1372 1368 writel_relaxed(reg->ivrp_paddr[i], base + REG_MMU_IVRP_PADDR); 1373 - writel(m4u_dom->cfg.arm_v7s_cfg.ttbr & MMU_PT_ADDR_MASK, 1374 - base + REG_MMU_PT_BASE_ADDR); 1369 + writel(m4u_dom->cfg.arm_v7s_cfg.ttbr, base + REG_MMU_PT_BASE_ADDR); 1375 1370 } while (++i < data->plat_data->banks_num); 1376 1371 1377 1372 /* ··· 1404 1401 static const struct mtk_iommu_plat_data mt6779_data = { 1405 1402 .m4u_plat = M4U_MT6779, 1406 1403 .flags = HAS_SUB_COMM_2BITS | OUT_ORDER_WR_EN | WR_THROT_EN | 1407 - MTK_IOMMU_TYPE_MM, 1404 + MTK_IOMMU_TYPE_MM | PGTABLE_PA_35_EN, 1408 1405 .inv_sel_reg = REG_MMU_INV_SEL_GEN2, 1409 1406 .banks_num = 1, 1410 1407 .banks_enable = {true},
-5
drivers/iommu/mtk_iommu_v1.c
··· 532 532 struct device *larbdev; 533 533 unsigned int larbid; 534 534 535 - if (!fwspec || fwspec->ops != &mtk_iommu_v1_ops) 536 - return; 537 - 538 535 data = dev_iommu_priv_get(dev); 539 536 larbid = mt2701_m4u_to_larb(fwspec->ids[0]); 540 537 larbdev = data->larb_imu[larbid].dev; 541 538 device_link_remove(dev, larbdev); 542 - 543 - iommu_fwspec_free(dev); 544 539 } 545 540 546 541 static int mtk_iommu_v1_hw_init(const struct mtk_iommu_v1_data *data)
-11
drivers/iommu/sprd-iommu.c
··· 383 383 return &sdev->iommu; 384 384 } 385 385 386 - static void sprd_iommu_release_device(struct device *dev) 387 - { 388 - struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); 389 - 390 - if (!fwspec || fwspec->ops != &sprd_iommu_ops) 391 - return; 392 - 393 - iommu_fwspec_free(dev); 394 - } 395 - 396 386 static struct iommu_group *sprd_iommu_device_group(struct device *dev) 397 387 { 398 388 struct sprd_iommu_device *sdev = dev_iommu_priv_get(dev); ··· 407 417 static const struct iommu_ops sprd_iommu_ops = { 408 418 .domain_alloc = sprd_iommu_domain_alloc, 409 419 .probe_device = sprd_iommu_probe_device, 410 - .release_device = sprd_iommu_release_device, 411 420 .device_group = sprd_iommu_device_group, 412 421 .of_xlate = sprd_iommu_of_xlate, 413 422 .pgsize_bitmap = ~0UL << SPRD_IOMMU_PAGE_SHIFT,
-3
drivers/iommu/sun50i-iommu.c
··· 738 738 return &iommu->iommu; 739 739 } 740 740 741 - static void sun50i_iommu_release_device(struct device *dev) {} 742 - 743 741 static struct iommu_group *sun50i_iommu_device_group(struct device *dev) 744 742 { 745 743 struct sun50i_iommu *iommu = sun50i_iommu_from_dev(dev); ··· 762 764 .domain_alloc = sun50i_iommu_domain_alloc, 763 765 .of_xlate = sun50i_iommu_of_xlate, 764 766 .probe_device = sun50i_iommu_probe_device, 765 - .release_device = sun50i_iommu_release_device, 766 767 .default_domain_ops = &(const struct iommu_domain_ops) { 767 768 .attach_dev = sun50i_iommu_attach_device, 768 769 .detach_dev = sun50i_iommu_detach_device,
-5
drivers/iommu/tegra-gart.c
··· 246 246 return &gart_handle->iommu; 247 247 } 248 248 249 - static void gart_iommu_release_device(struct device *dev) 250 - { 251 - } 252 - 253 249 static int gart_iommu_of_xlate(struct device *dev, 254 250 struct of_phandle_args *args) 255 251 { ··· 269 273 static const struct iommu_ops gart_iommu_ops = { 270 274 .domain_alloc = gart_iommu_domain_alloc, 271 275 .probe_device = gart_iommu_probe_device, 272 - .release_device = gart_iommu_release_device, 273 276 .device_group = generic_device_group, 274 277 .pgsize_bitmap = GART_IOMMU_PGSIZES, 275 278 .of_xlate = gart_iommu_of_xlate,
-3
drivers/iommu/tegra-smmu.c
··· 864 864 return &smmu->iommu; 865 865 } 866 866 867 - static void tegra_smmu_release_device(struct device *dev) {} 868 - 869 867 static const struct tegra_smmu_group_soc * 870 868 tegra_smmu_find_group(struct tegra_smmu *smmu, unsigned int swgroup) 871 869 { ··· 964 966 static const struct iommu_ops tegra_smmu_ops = { 965 967 .domain_alloc = tegra_smmu_domain_alloc, 966 968 .probe_device = tegra_smmu_probe_device, 967 - .release_device = tegra_smmu_release_device, 968 969 .device_group = tegra_smmu_device_group, 969 970 .of_xlate = tegra_smmu_of_xlate, 970 971 .pgsize_bitmap = SZ_4K,
+15 -16
drivers/iommu/virtio-iommu.c
··· 788 788 return 0; 789 789 } 790 790 791 - static int viommu_map(struct iommu_domain *domain, unsigned long iova, 792 - phys_addr_t paddr, size_t size, int prot, gfp_t gfp) 791 + static int viommu_map_pages(struct iommu_domain *domain, unsigned long iova, 792 + phys_addr_t paddr, size_t pgsize, size_t pgcount, 793 + int prot, gfp_t gfp, size_t *mapped) 793 794 { 794 795 int ret; 795 796 u32 flags; 797 + size_t size = pgsize * pgcount; 796 798 u64 end = iova + size - 1; 797 799 struct virtio_iommu_req_map map; 798 800 struct viommu_domain *vdomain = to_viommu_domain(domain); ··· 825 823 ret = viommu_send_req_sync(vdomain->viommu, &map, sizeof(map)); 826 824 if (ret) 827 825 viommu_del_mappings(vdomain, iova, end); 826 + else if (mapped) 827 + *mapped = size; 828 828 829 829 return ret; 830 830 } 831 831 832 - static size_t viommu_unmap(struct iommu_domain *domain, unsigned long iova, 833 - size_t size, struct iommu_iotlb_gather *gather) 832 + static size_t viommu_unmap_pages(struct iommu_domain *domain, unsigned long iova, 833 + size_t pgsize, size_t pgcount, 834 + struct iommu_iotlb_gather *gather) 834 835 { 835 836 int ret = 0; 836 837 size_t unmapped; 837 838 struct virtio_iommu_req_unmap unmap; 838 839 struct viommu_domain *vdomain = to_viommu_domain(domain); 840 + size_t size = pgsize * pgcount; 839 841 840 842 unmapped = viommu_del_mappings(vdomain, iova, iova + size - 1); 841 843 if (unmapped < size) ··· 970 964 return &viommu->iommu; 971 965 972 966 err_free_dev: 973 - generic_iommu_put_resv_regions(dev, &vdev->resv_regions); 967 + iommu_put_resv_regions(dev, &vdev->resv_regions); 974 968 kfree(vdev); 975 969 976 970 return ERR_PTR(ret); ··· 987 981 988 982 static void viommu_release_device(struct device *dev) 989 983 { 990 - struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); 991 - struct viommu_endpoint *vdev; 984 + struct viommu_endpoint *vdev = dev_iommu_priv_get(dev); 992 985 993 - if (!fwspec || fwspec->ops != &viommu_ops) 994 - return; 995 - 996 - vdev = dev_iommu_priv_get(dev); 997 - 998 - generic_iommu_put_resv_regions(dev, &vdev->resv_regions); 986 + iommu_put_resv_regions(dev, &vdev->resv_regions); 999 987 kfree(vdev); 1000 988 } 1001 989 ··· 1013 1013 .release_device = viommu_release_device, 1014 1014 .device_group = viommu_device_group, 1015 1015 .get_resv_regions = viommu_get_resv_regions, 1016 - .put_resv_regions = generic_iommu_put_resv_regions, 1017 1016 .of_xlate = viommu_of_xlate, 1018 1017 .owner = THIS_MODULE, 1019 1018 .default_domain_ops = &(const struct iommu_domain_ops) { 1020 1019 .attach_dev = viommu_attach_dev, 1021 - .map = viommu_map, 1022 - .unmap = viommu_unmap, 1020 + .map_pages = viommu_map_pages, 1021 + .unmap_pages = viommu_unmap_pages, 1023 1022 .iova_to_phys = viommu_iova_to_phys, 1024 1023 .iotlb_sync = viommu_iotlb_sync, 1025 1024 .free = viommu_domain_free,
+11 -3
include/linux/acpi_iort.h
··· 33 33 enum irq_domain_bus_token bus_token); 34 34 void acpi_configure_pmsi_domain(struct device *dev); 35 35 int iort_pmsi_get_dev_id(struct device *dev, u32 *dev_id); 36 + void iort_get_rmr_sids(struct fwnode_handle *iommu_fwnode, 37 + struct list_head *head); 38 + void iort_put_rmr_sids(struct fwnode_handle *iommu_fwnode, 39 + struct list_head *head); 36 40 /* IOMMU interface */ 37 41 int iort_dma_get_ranges(struct device *dev, u64 *size); 38 42 int iort_iommu_configure_id(struct device *dev, const u32 *id_in); 39 - int iort_iommu_msi_get_resv_regions(struct device *dev, struct list_head *head); 43 + void iort_iommu_get_resv_regions(struct device *dev, struct list_head *head); 40 44 phys_addr_t acpi_iort_dma_get_max_cpu_address(void); 41 45 #else 42 46 static inline void acpi_iort_init(void) { } ··· 50 46 struct device *dev, u32 id, enum irq_domain_bus_token bus_token) 51 47 { return NULL; } 52 48 static inline void acpi_configure_pmsi_domain(struct device *dev) { } 49 + static inline 50 + void iort_get_rmr_sids(struct fwnode_handle *iommu_fwnode, struct list_head *head) { } 51 + static inline 52 + void iort_put_rmr_sids(struct fwnode_handle *iommu_fwnode, struct list_head *head) { } 53 53 /* IOMMU interface */ 54 54 static inline int iort_dma_get_ranges(struct device *dev, u64 *size) 55 55 { return -ENODEV; } 56 56 static inline int iort_iommu_configure_id(struct device *dev, const u32 *id_in) 57 57 { return -ENODEV; } 58 58 static inline 59 - int iort_iommu_msi_get_resv_regions(struct device *dev, struct list_head *head) 60 - { return 0; } 59 + void iort_iommu_get_resv_regions(struct device *dev, struct list_head *head) 60 + { } 61 61 62 62 static inline phys_addr_t acpi_iort_dma_get_max_cpu_address(void) 63 63 { return PHYS_ADDR_MAX; }
+4
include/linux/amd-iommu.h
··· 206 206 u64 *value); 207 207 struct amd_iommu *get_amd_iommu(unsigned int idx); 208 208 209 + #ifdef CONFIG_AMD_MEM_ENCRYPT 210 + int amd_iommu_snp_enable(void); 211 + #endif 212 + 209 213 #endif /* _ASM_X86_AMD_IOMMU_H */
+1 -5
include/linux/dmar.h
··· 18 18 19 19 struct acpi_dmar_header; 20 20 21 - #ifdef CONFIG_X86 22 - # define DMAR_UNITS_SUPPORTED MAX_IO_APICS 23 - #else 24 - # define DMAR_UNITS_SUPPORTED 64 25 - #endif 21 + #define DMAR_UNITS_SUPPORTED 1024 26 22 27 23 /* DMAR Flags */ 28 24 #define DMAR_INTR_REMAP 0x1
+21 -14
include/linux/intel-iommu.h drivers/iommu/intel/iommu.h
··· 21 21 #include <linux/dmar.h> 22 22 #include <linux/ioasid.h> 23 23 #include <linux/bitfield.h> 24 + #include <linux/xarray.h> 24 25 25 26 #include <asm/cacheflush.h> 26 27 #include <asm/iommu.h> ··· 481 480 #define VTD_FLAG_SVM_CAPABLE (1 << 2) 482 481 483 482 extern int intel_iommu_sm; 484 - extern spinlock_t device_domain_lock; 485 483 486 484 #define sm_supported(iommu) (intel_iommu_sm && ecap_smts((iommu)->ecap)) 487 485 #define pasid_supported(iommu) (sm_supported(iommu) && \ ··· 525 525 */ 526 526 #define DOMAIN_FLAG_USE_FIRST_LEVEL BIT(1) 527 527 528 - struct dmar_domain { 529 - int nid; /* node id */ 530 - 531 - unsigned int iommu_refcnt[DMAR_UNITS_SUPPORTED]; 532 - /* Refcount of devices per iommu */ 533 - 534 - 535 - u16 iommu_did[DMAR_UNITS_SUPPORTED]; 536 - /* Domain ids per IOMMU. Use u16 since 528 + struct iommu_domain_info { 529 + struct intel_iommu *iommu; 530 + unsigned int refcnt; /* Refcount of devices per iommu */ 531 + u16 did; /* Domain ids per IOMMU. Use u16 since 537 532 * domain ids are 16 bit wide according 538 533 * to VT-d spec, section 9.3 */ 534 + }; 535 + 536 + struct dmar_domain { 537 + int nid; /* node id */ 538 + struct xarray iommu_array; /* Attached IOMMU array */ 539 539 540 540 u8 has_iotlb_device: 1; 541 541 u8 iommu_coherency: 1; /* indicate coherency of iommu access */ 542 542 u8 force_snooping : 1; /* Create IOPTEs with snoop control */ 543 543 u8 set_pte_snp:1; 544 544 545 + spinlock_t lock; /* Protect device tracking lists */ 545 546 struct list_head devices; /* all devices' list */ 546 - struct iova_domain iovad; /* iova's that belong to this domain */ 547 547 548 548 struct dma_pte *pgd; /* virtual address */ 549 549 int gaw; /* max guest address width */ ··· 611 611 /* PCI domain-device relationship */ 612 612 struct device_domain_info { 613 613 struct list_head link; /* link to domain siblings */ 614 - struct list_head global; /* link to global list */ 615 614 u32 segment; /* PCI segment number */ 616 615 u8 bus; /* PCI bus number */ 617 616 u8 devfn; /* PCI devfn number */ ··· 639 640 static inline struct dmar_domain *to_dmar_domain(struct iommu_domain *dom) 640 641 { 641 642 return container_of(dom, struct dmar_domain, domain); 643 + } 644 + 645 + /* Retrieve the domain ID which has allocated to the domain */ 646 + static inline u16 647 + domain_id_iommu(struct dmar_domain *domain, struct intel_iommu *iommu) 648 + { 649 + struct iommu_domain_info *info = 650 + xa_load(&domain->iommu_array, iommu->seq_id); 651 + 652 + return info->did; 642 653 } 643 654 644 655 /* ··· 736 727 737 728 void *alloc_pgtable_page(int node); 738 729 void free_pgtable_page(void *vaddr); 739 - struct intel_iommu *domain_get_iommu(struct dmar_domain *domain); 740 730 void iommu_flush_write_buffer(struct intel_iommu *iommu); 741 731 int intel_iommu_enable_pasid(struct intel_iommu *iommu, struct device *dev); 742 732 struct intel_iommu *device_to_iommu(struct device *dev, u8 *bus, u8 *devfn); ··· 795 787 extern int iommu_calculate_max_sagaw(struct intel_iommu *iommu); 796 788 extern int dmar_disabled; 797 789 extern int intel_iommu_enabled; 798 - extern int intel_iommu_gfx_mapped; 799 790 #else 800 791 static inline int iommu_calculate_agaw(struct intel_iommu *iommu) 801 792 {
+10 -5
include/linux/io-pgtable.h
··· 74 74 * to support up to 35 bits PA where the bit32, bit33 and bit34 are 75 75 * encoded in the bit9, bit4 and bit5 of the PTE respectively. 76 76 * 77 + * IO_PGTABLE_QUIRK_ARM_MTK_TTBR_EXT: (ARM v7s format) MediaTek IOMMUs 78 + * extend the translation table base support up to 35 bits PA, the 79 + * encoding format is same with IO_PGTABLE_QUIRK_ARM_MTK_EXT. 80 + * 77 81 * IO_PGTABLE_QUIRK_ARM_TTBR1: (ARM LPAE format) Configure the table 78 82 * for use in the upper half of a split address space. 79 83 * 80 84 * IO_PGTABLE_QUIRK_ARM_OUTER_WBWA: Override the outer-cacheability 81 85 * attributes set in the TCR for a non-coherent page-table walker. 82 86 */ 83 - #define IO_PGTABLE_QUIRK_ARM_NS BIT(0) 84 - #define IO_PGTABLE_QUIRK_NO_PERMS BIT(1) 85 - #define IO_PGTABLE_QUIRK_ARM_MTK_EXT BIT(3) 86 - #define IO_PGTABLE_QUIRK_ARM_TTBR1 BIT(5) 87 - #define IO_PGTABLE_QUIRK_ARM_OUTER_WBWA BIT(6) 87 + #define IO_PGTABLE_QUIRK_ARM_NS BIT(0) 88 + #define IO_PGTABLE_QUIRK_NO_PERMS BIT(1) 89 + #define IO_PGTABLE_QUIRK_ARM_MTK_EXT BIT(3) 90 + #define IO_PGTABLE_QUIRK_ARM_MTK_TTBR_EXT BIT(4) 91 + #define IO_PGTABLE_QUIRK_ARM_TTBR1 BIT(5) 92 + #define IO_PGTABLE_QUIRK_ARM_OUTER_WBWA BIT(6) 88 93 unsigned long quirks; 89 94 unsigned long pgsize_bitmap; 90 95 unsigned int ias;
+11 -16
include/linux/iommu.h
··· 135 135 * @length: Length of the region in bytes 136 136 * @prot: IOMMU Protection flags (READ/WRITE/...) 137 137 * @type: Type of the reserved region 138 + * @free: Callback to free associated memory allocations 138 139 */ 139 140 struct iommu_resv_region { 140 141 struct list_head list; ··· 143 142 size_t length; 144 143 int prot; 145 144 enum iommu_resv_type type; 145 + void (*free)(struct device *dev, struct iommu_resv_region *region); 146 + }; 147 + 148 + struct iommu_iort_rmr_data { 149 + struct iommu_resv_region rr; 150 + 151 + /* Stream IDs associated with IORT RMR entry */ 152 + const u32 *sids; 153 + u32 num_sids; 146 154 }; 147 155 148 156 /** ··· 164 154 * supported, this feature must be enabled before and 165 155 * disabled after %IOMMU_DEV_FEAT_SVA. 166 156 * 167 - * Device drivers query whether a feature is supported using 168 - * iommu_dev_has_feature(), and enable it using iommu_dev_enable_feature(). 157 + * Device drivers enable a feature using iommu_dev_enable_feature(). 169 158 */ 170 159 enum iommu_dev_features { 171 160 IOMMU_DEV_FEAT_SVA, ··· 209 200 * group and attached to the groups domain 210 201 * @device_group: find iommu group for a particular device 211 202 * @get_resv_regions: Request list of reserved regions for a device 212 - * @put_resv_regions: Free list of reserved regions for a device 213 203 * @of_xlate: add OF master IDs to iommu grouping 214 204 * @is_attach_deferred: Check if domain attach should be deferred from iommu 215 205 * driver init to device driver init (default no) 216 206 * @dev_has/enable/disable_feat: per device entries to check/enable/disable 217 207 * iommu specific features. 218 - * @dev_feat_enabled: check enabled feature 219 208 * @sva_bind: Bind process address space to device 220 209 * @sva_unbind: Unbind process address space from device 221 210 * @sva_get_pasid: Get PASID associated to a SVA handle ··· 239 232 240 233 /* Request/Free a list of reserved regions for a device */ 241 234 void (*get_resv_regions)(struct device *dev, struct list_head *list); 242 - void (*put_resv_regions)(struct device *dev, struct list_head *list); 243 235 244 236 int (*of_xlate)(struct device *dev, struct of_phandle_args *args); 245 237 bool (*is_attach_deferred)(struct device *dev); 246 238 247 239 /* Per device IOMMU features */ 248 - bool (*dev_has_feat)(struct device *dev, enum iommu_dev_features f); 249 - bool (*dev_feat_enabled)(struct device *dev, enum iommu_dev_features f); 250 240 int (*dev_enable_feat)(struct device *dev, enum iommu_dev_features f); 251 241 int (*dev_disable_feat)(struct device *dev, enum iommu_dev_features f); 252 242 ··· 452 448 453 449 extern void iommu_get_resv_regions(struct device *dev, struct list_head *list); 454 450 extern void iommu_put_resv_regions(struct device *dev, struct list_head *list); 455 - extern void generic_iommu_put_resv_regions(struct device *dev, 456 - struct list_head *list); 457 451 extern void iommu_set_default_passthrough(bool cmd_line); 458 452 extern void iommu_set_default_translated(bool cmd_line); 459 453 extern bool iommu_default_passthrough(void); ··· 664 662 665 663 int iommu_dev_enable_feature(struct device *dev, enum iommu_dev_features f); 666 664 int iommu_dev_disable_feature(struct device *dev, enum iommu_dev_features f); 667 - bool iommu_dev_feature_enabled(struct device *dev, enum iommu_dev_features f); 668 665 669 666 struct iommu_sva *iommu_sva_bind_device(struct device *dev, 670 667 struct mm_struct *mm, ··· 988 987 const struct iommu_ops *iommu_ops_from_fwnode(struct fwnode_handle *fwnode) 989 988 { 990 989 return NULL; 991 - } 992 - 993 - static inline bool 994 - iommu_dev_feature_enabled(struct device *dev, enum iommu_dev_features feat) 995 - { 996 - return false; 997 990 } 998 991 999 992 static inline int
-2
include/linux/tboot.h
··· 126 126 extern void tboot_shutdown(u32 shutdown_type); 127 127 extern struct acpi_table_header *tboot_get_dmar_table( 128 128 struct acpi_table_header *dmar_tbl); 129 - extern int tboot_force_iommu(void); 130 129 131 130 #else 132 131 ··· 135 136 #define tboot_sleep(sleep_state, pm1a_control, pm1b_control) \ 136 137 do { } while (0) 137 138 #define tboot_get_dmar_table(dmar_tbl) (dmar_tbl) 138 - #define tboot_force_iommu() 0 139 139 140 140 #endif /* !CONFIG_INTEL_TXT */ 141 141
+6 -1
include/trace/events/intel_iommu.h drivers/iommu/intel/trace.h
··· 13 13 #define _TRACE_INTEL_IOMMU_H 14 14 15 15 #include <linux/tracepoint.h> 16 - #include <linux/intel-iommu.h> 16 + 17 + #include "iommu.h" 17 18 18 19 #define MSG_MAX 256 19 20 ··· 92 91 #endif /* _TRACE_INTEL_IOMMU_H */ 93 92 94 93 /* This part must be outside protection */ 94 + #undef TRACE_INCLUDE_PATH 95 + #undef TRACE_INCLUDE_FILE 96 + #define TRACE_INCLUDE_PATH ../../drivers/iommu/intel/ 97 + #define TRACE_INCLUDE_FILE trace 95 98 #include <trace/define_trace.h>