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

Merge tag 'iommu-updates-v3.10' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu

Pull IOMMU updates from Joerg Roedel:
"The updates are mostly about the x86 IOMMUs this time.

Exceptions are the groundwork for the PAMU IOMMU from Freescale (for a
PPC platform) and an extension to the IOMMU group interface.

On the x86 side this includes a workaround for VT-d to disable
interrupt remapping on broken chipsets. On the AMD-Vi side the most
important new feature is a kernel command-line interface to override
broken information in IVRS ACPI tables and get interrupt remapping
working this way.

Besides that there are small fixes all over the place."

* tag 'iommu-updates-v3.10' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu: (24 commits)
iommu/tegra: Fix printk formats for dma_addr_t
iommu: Add a function to find an iommu group by id
iommu/vt-d: Remove warning for HPET scope type
iommu: Move swap_pci_ref function to drivers/iommu/pci.h.
iommu/vt-d: Disable translation if already enabled
iommu/amd: fix error return code in early_amd_iommu_init()
iommu/AMD: Per-thread IOMMU Interrupt Handling
iommu: Include linux/err.h
iommu/amd: Workaround for ERBT1312
iommu/amd: Document ivrs_ioapic and ivrs_hpet parameters
iommu/amd: Don't report firmware bugs with cmd-line ivrs overrides
iommu/amd: Add ioapic and hpet ivrs override
iommu/amd: Add early maps for ioapic and hpet
iommu/amd: Extend IVRS special device data structure
iommu/amd: Move add_special_device() to __init
iommu: Fix compile warnings with forward declarations
iommu/amd: Properly initialize irq-table lock
iommu/amd: Use AMD specific data structure for irq remapping
iommu/amd: Remove map_sg_no_iommu()
iommu/vt-d: add quirk for broken interrupt remapping on 55XX chipsets
...

+380 -131
+14
Documentation/kernel-parameters.txt
··· 1277 1277 1278 1278 iucv= [HW,NET] 1279 1279 1280 + ivrs_ioapic [HW,X86_64] 1281 + Provide an override to the IOAPIC-ID<->DEVICE-ID 1282 + mapping provided in the IVRS ACPI table. For 1283 + example, to map IOAPIC-ID decimal 10 to 1284 + PCI device 00:14.0 write the parameter as: 1285 + ivrs_ioapic[10]=00:14.0 1286 + 1287 + ivrs_hpet [HW,X86_64] 1288 + Provide an override to the HPET-ID<->DEVICE-ID 1289 + mapping provided in the IVRS ACPI table. For 1290 + example, to map HPET-ID decimal 0 to 1291 + PCI device 00:14.0 write the parameter as: 1292 + ivrs_hpet[0]=00:14.0 1293 + 1280 1294 js= [HW,JOY] Analog joystick 1281 1295 See Documentation/input/joystick.txt. 1282 1296
+9
arch/x86/include/asm/irq_remapping.h
··· 24 24 25 25 #include <asm/io_apic.h> 26 26 27 + struct IO_APIC_route_entry; 28 + struct io_apic_irq_attr; 29 + struct irq_chip; 30 + struct msi_msg; 31 + struct pci_dev; 32 + struct irq_cfg; 33 + 27 34 #ifdef CONFIG_IRQ_REMAP 28 35 29 36 extern void setup_irq_remapping_ops(void); 30 37 extern int irq_remapping_supported(void); 38 + extern void set_irq_remapping_broken(void); 31 39 extern int irq_remapping_prepare(void); 32 40 extern int irq_remapping_enable(void); 33 41 extern void irq_remapping_disable(void); ··· 62 54 63 55 static inline void setup_irq_remapping_ops(void) { } 64 56 static inline int irq_remapping_supported(void) { return 0; } 57 + static inline void set_irq_remapping_broken(void) { } 65 58 static inline int irq_remapping_prepare(void) { return -ENODEV; } 66 59 static inline int irq_remapping_enable(void) { return -ENODEV; } 67 60 static inline void irq_remapping_disable(void) { }
+20
arch/x86/kernel/early-quirks.c
··· 18 18 #include <asm/apic.h> 19 19 #include <asm/iommu.h> 20 20 #include <asm/gart.h> 21 + #include <asm/irq_remapping.h> 21 22 22 23 static void __init fix_hypertransport_config(int num, int slot, int func) 23 24 { ··· 193 192 } 194 193 #endif 195 194 195 + static void __init intel_remapping_check(int num, int slot, int func) 196 + { 197 + u8 revision; 198 + 199 + revision = read_pci_config_byte(num, slot, func, PCI_REVISION_ID); 200 + 201 + /* 202 + * Revision 0x13 of this chipset supports irq remapping 203 + * but has an erratum that breaks its behavior, flag it as such 204 + */ 205 + if (revision == 0x13) 206 + set_irq_remapping_broken(); 207 + 208 + } 209 + 196 210 #define QFLAG_APPLY_ONCE 0x1 197 211 #define QFLAG_APPLIED 0x2 198 212 #define QFLAG_DONE (QFLAG_APPLY_ONCE|QFLAG_APPLIED) ··· 237 221 PCI_CLASS_SERIAL_SMBUS, PCI_ANY_ID, 0, ati_bugs }, 238 222 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_SBX00_SMBUS, 239 223 PCI_CLASS_SERIAL_SMBUS, PCI_ANY_ID, 0, ati_bugs_contd }, 224 + { PCI_VENDOR_ID_INTEL, 0x3403, PCI_CLASS_BRIDGE_HOST, 225 + PCI_BASE_CLASS_BRIDGE, 0, intel_remapping_check }, 226 + { PCI_VENDOR_ID_INTEL, 0x3406, PCI_CLASS_BRIDGE_HOST, 227 + PCI_BASE_CLASS_BRIDGE, 0, intel_remapping_check }, 240 228 {} 241 229 }; 242 230
+64 -81
drivers/iommu/amd_iommu.c
··· 46 46 #include "amd_iommu_proto.h" 47 47 #include "amd_iommu_types.h" 48 48 #include "irq_remapping.h" 49 + #include "pci.h" 49 50 50 51 #define CMD_SET_TYPE(cmd, t) ((cmd)->data[1] |= ((t) << 28)) 51 52 ··· 262 261 return false; 263 262 264 263 return true; 265 - } 266 - 267 - static void swap_pci_ref(struct pci_dev **from, struct pci_dev *to) 268 - { 269 - pci_dev_put(*from); 270 - *from = to; 271 264 } 272 265 273 266 static struct pci_bus *find_hosted_bus(struct pci_bus *bus) ··· 696 701 static void iommu_poll_events(struct amd_iommu *iommu) 697 702 { 698 703 u32 head, tail; 699 - unsigned long flags; 700 - 701 - spin_lock_irqsave(&iommu->lock, flags); 702 704 703 705 head = readl(iommu->mmio_base + MMIO_EVT_HEAD_OFFSET); 704 706 tail = readl(iommu->mmio_base + MMIO_EVT_TAIL_OFFSET); ··· 706 714 } 707 715 708 716 writel(head, iommu->mmio_base + MMIO_EVT_HEAD_OFFSET); 709 - 710 - spin_unlock_irqrestore(&iommu->lock, flags); 711 717 } 712 718 713 719 static void iommu_handle_ppr_entry(struct amd_iommu *iommu, u64 *raw) ··· 730 740 731 741 static void iommu_poll_ppr_log(struct amd_iommu *iommu) 732 742 { 733 - unsigned long flags; 734 743 u32 head, tail; 735 744 736 745 if (iommu->ppr_log == NULL) 737 746 return; 738 - 739 - /* enable ppr interrupts again */ 740 - writel(MMIO_STATUS_PPR_INT_MASK, iommu->mmio_base + MMIO_STATUS_OFFSET); 741 - 742 - spin_lock_irqsave(&iommu->lock, flags); 743 747 744 748 head = readl(iommu->mmio_base + MMIO_PPR_HEAD_OFFSET); 745 749 tail = readl(iommu->mmio_base + MMIO_PPR_TAIL_OFFSET); ··· 770 786 head = (head + PPR_ENTRY_SIZE) % PPR_LOG_SIZE; 771 787 writel(head, iommu->mmio_base + MMIO_PPR_HEAD_OFFSET); 772 788 773 - /* 774 - * Release iommu->lock because ppr-handling might need to 775 - * re-acquire it 776 - */ 777 - spin_unlock_irqrestore(&iommu->lock, flags); 778 - 779 789 /* Handle PPR entry */ 780 790 iommu_handle_ppr_entry(iommu, entry); 781 - 782 - spin_lock_irqsave(&iommu->lock, flags); 783 791 784 792 /* Refresh ring-buffer information */ 785 793 head = readl(iommu->mmio_base + MMIO_PPR_HEAD_OFFSET); 786 794 tail = readl(iommu->mmio_base + MMIO_PPR_TAIL_OFFSET); 787 795 } 788 - 789 - spin_unlock_irqrestore(&iommu->lock, flags); 790 796 } 791 797 792 798 irqreturn_t amd_iommu_int_thread(int irq, void *data) 793 799 { 794 - struct amd_iommu *iommu; 800 + struct amd_iommu *iommu = (struct amd_iommu *) data; 801 + u32 status = readl(iommu->mmio_base + MMIO_STATUS_OFFSET); 795 802 796 - for_each_iommu(iommu) { 797 - iommu_poll_events(iommu); 798 - iommu_poll_ppr_log(iommu); 803 + while (status & (MMIO_STATUS_EVT_INT_MASK | MMIO_STATUS_PPR_INT_MASK)) { 804 + /* Enable EVT and PPR interrupts again */ 805 + writel((MMIO_STATUS_EVT_INT_MASK | MMIO_STATUS_PPR_INT_MASK), 806 + iommu->mmio_base + MMIO_STATUS_OFFSET); 807 + 808 + if (status & MMIO_STATUS_EVT_INT_MASK) { 809 + pr_devel("AMD-Vi: Processing IOMMU Event Log\n"); 810 + iommu_poll_events(iommu); 811 + } 812 + 813 + if (status & MMIO_STATUS_PPR_INT_MASK) { 814 + pr_devel("AMD-Vi: Processing IOMMU PPR Log\n"); 815 + iommu_poll_ppr_log(iommu); 816 + } 817 + 818 + /* 819 + * Hardware bug: ERBT1312 820 + * When re-enabling interrupt (by writing 1 821 + * to clear the bit), the hardware might also try to set 822 + * the interrupt bit in the event status register. 823 + * In this scenario, the bit will be set, and disable 824 + * subsequent interrupts. 825 + * 826 + * Workaround: The IOMMU driver should read back the 827 + * status register and check if the interrupt bits are cleared. 828 + * If not, driver will need to go through the interrupt handler 829 + * again and re-clear the bits 830 + */ 831 + status = readl(iommu->mmio_base + MMIO_STATUS_OFFSET); 799 832 } 800 - 801 833 return IRQ_HANDLED; 802 834 } 803 835 ··· 2839 2839 } 2840 2840 2841 2841 /* 2842 - * This is a special map_sg function which is used if we should map a 2843 - * device which is not handled by an AMD IOMMU in the system. 2844 - */ 2845 - static int map_sg_no_iommu(struct device *dev, struct scatterlist *sglist, 2846 - int nelems, int dir) 2847 - { 2848 - struct scatterlist *s; 2849 - int i; 2850 - 2851 - for_each_sg(sglist, s, nelems, i) { 2852 - s->dma_address = (dma_addr_t)sg_phys(s); 2853 - s->dma_length = s->length; 2854 - } 2855 - 2856 - return nelems; 2857 - } 2858 - 2859 - /* 2860 2842 * The exported map_sg function for dma_ops (handles scatter-gather 2861 2843 * lists). 2862 2844 */ ··· 2857 2875 INC_STATS_COUNTER(cnt_map_sg); 2858 2876 2859 2877 domain = get_domain(dev); 2860 - if (PTR_ERR(domain) == -EINVAL) 2861 - return map_sg_no_iommu(dev, sglist, nelems, dir); 2862 - else if (IS_ERR(domain)) 2878 + if (IS_ERR(domain)) 2863 2879 return 0; 2864 2880 2865 2881 dma_mask = *dev->dma_mask; ··· 3390 3410 } 3391 3411 3392 3412 static phys_addr_t amd_iommu_iova_to_phys(struct iommu_domain *dom, 3393 - unsigned long iova) 3413 + dma_addr_t iova) 3394 3414 { 3395 3415 struct protection_domain *domain = dom->priv; 3396 3416 unsigned long offset_mask; ··· 3927 3947 if (!table) 3928 3948 goto out; 3929 3949 3950 + /* Initialize table spin-lock */ 3951 + spin_lock_init(&table->lock); 3952 + 3930 3953 if (ioapic) 3931 3954 /* Keep the first 32 indexes free for IOAPIC interrupts */ 3932 3955 table->min_index = 32; ··· 3990 4007 c = 0; 3991 4008 3992 4009 if (c == count) { 3993 - struct irq_2_iommu *irte_info; 4010 + struct irq_2_irte *irte_info; 3994 4011 3995 4012 for (; c != 0; --c) 3996 4013 table->table[index - c + 1] = IRTE_ALLOCATED; ··· 3998 4015 index -= count - 1; 3999 4016 4000 4017 cfg->remapped = 1; 4001 - irte_info = &cfg->irq_2_iommu; 4002 - irte_info->sub_handle = devid; 4003 - irte_info->irte_index = index; 4018 + irte_info = &cfg->irq_2_irte; 4019 + irte_info->devid = devid; 4020 + irte_info->index = index; 4004 4021 4005 4022 goto out; 4006 4023 } ··· 4081 4098 struct io_apic_irq_attr *attr) 4082 4099 { 4083 4100 struct irq_remap_table *table; 4084 - struct irq_2_iommu *irte_info; 4101 + struct irq_2_irte *irte_info; 4085 4102 struct irq_cfg *cfg; 4086 4103 union irte irte; 4087 4104 int ioapic_id; ··· 4093 4110 if (!cfg) 4094 4111 return -EINVAL; 4095 4112 4096 - irte_info = &cfg->irq_2_iommu; 4113 + irte_info = &cfg->irq_2_irte; 4097 4114 ioapic_id = mpc_ioapic_id(attr->ioapic); 4098 4115 devid = get_ioapic_devid(ioapic_id); 4099 4116 ··· 4108 4125 4109 4126 /* Setup IRQ remapping info */ 4110 4127 cfg->remapped = 1; 4111 - irte_info->sub_handle = devid; 4112 - irte_info->irte_index = index; 4128 + irte_info->devid = devid; 4129 + irte_info->index = index; 4113 4130 4114 4131 /* Setup IRTE for IOMMU */ 4115 4132 irte.val = 0; ··· 4143 4160 static int set_affinity(struct irq_data *data, const struct cpumask *mask, 4144 4161 bool force) 4145 4162 { 4146 - struct irq_2_iommu *irte_info; 4163 + struct irq_2_irte *irte_info; 4147 4164 unsigned int dest, irq; 4148 4165 struct irq_cfg *cfg; 4149 4166 union irte irte; ··· 4154 4171 4155 4172 cfg = data->chip_data; 4156 4173 irq = data->irq; 4157 - irte_info = &cfg->irq_2_iommu; 4174 + irte_info = &cfg->irq_2_irte; 4158 4175 4159 4176 if (!cpumask_intersects(mask, cpu_online_mask)) 4160 4177 return -EINVAL; 4161 4178 4162 - if (get_irte(irte_info->sub_handle, irte_info->irte_index, &irte)) 4179 + if (get_irte(irte_info->devid, irte_info->index, &irte)) 4163 4180 return -EBUSY; 4164 4181 4165 4182 if (assign_irq_vector(irq, cfg, mask)) ··· 4175 4192 irte.fields.vector = cfg->vector; 4176 4193 irte.fields.destination = dest; 4177 4194 4178 - modify_irte(irte_info->sub_handle, irte_info->irte_index, irte); 4195 + modify_irte(irte_info->devid, irte_info->index, irte); 4179 4196 4180 4197 if (cfg->move_in_progress) 4181 4198 send_cleanup_vector(cfg); ··· 4187 4204 4188 4205 static int free_irq(int irq) 4189 4206 { 4190 - struct irq_2_iommu *irte_info; 4207 + struct irq_2_irte *irte_info; 4191 4208 struct irq_cfg *cfg; 4192 4209 4193 4210 cfg = irq_get_chip_data(irq); 4194 4211 if (!cfg) 4195 4212 return -EINVAL; 4196 4213 4197 - irte_info = &cfg->irq_2_iommu; 4214 + irte_info = &cfg->irq_2_irte; 4198 4215 4199 - free_irte(irte_info->sub_handle, irte_info->irte_index); 4216 + free_irte(irte_info->devid, irte_info->index); 4200 4217 4201 4218 return 0; 4202 4219 } ··· 4205 4222 unsigned int irq, unsigned int dest, 4206 4223 struct msi_msg *msg, u8 hpet_id) 4207 4224 { 4208 - struct irq_2_iommu *irte_info; 4225 + struct irq_2_irte *irte_info; 4209 4226 struct irq_cfg *cfg; 4210 4227 union irte irte; 4211 4228 ··· 4213 4230 if (!cfg) 4214 4231 return; 4215 4232 4216 - irte_info = &cfg->irq_2_iommu; 4233 + irte_info = &cfg->irq_2_irte; 4217 4234 4218 4235 irte.val = 0; 4219 4236 irte.fields.vector = cfg->vector; ··· 4222 4239 irte.fields.dm = apic->irq_dest_mode; 4223 4240 irte.fields.valid = 1; 4224 4241 4225 - modify_irte(irte_info->sub_handle, irte_info->irte_index, irte); 4242 + modify_irte(irte_info->devid, irte_info->index, irte); 4226 4243 4227 4244 msg->address_hi = MSI_ADDR_BASE_HI; 4228 4245 msg->address_lo = MSI_ADDR_BASE_LO; 4229 - msg->data = irte_info->irte_index; 4246 + msg->data = irte_info->index; 4230 4247 } 4231 4248 4232 4249 static int msi_alloc_irq(struct pci_dev *pdev, int irq, int nvec) ··· 4251 4268 static int msi_setup_irq(struct pci_dev *pdev, unsigned int irq, 4252 4269 int index, int offset) 4253 4270 { 4254 - struct irq_2_iommu *irte_info; 4271 + struct irq_2_irte *irte_info; 4255 4272 struct irq_cfg *cfg; 4256 4273 u16 devid; 4257 4274 ··· 4266 4283 return 0; 4267 4284 4268 4285 devid = get_device_id(&pdev->dev); 4269 - irte_info = &cfg->irq_2_iommu; 4286 + irte_info = &cfg->irq_2_irte; 4270 4287 4271 4288 cfg->remapped = 1; 4272 - irte_info->sub_handle = devid; 4273 - irte_info->irte_index = index + offset; 4289 + irte_info->devid = devid; 4290 + irte_info->index = index + offset; 4274 4291 4275 4292 return 0; 4276 4293 } 4277 4294 4278 4295 static int setup_hpet_msi(unsigned int irq, unsigned int id) 4279 4296 { 4280 - struct irq_2_iommu *irte_info; 4297 + struct irq_2_irte *irte_info; 4281 4298 struct irq_cfg *cfg; 4282 4299 int index, devid; 4283 4300 ··· 4285 4302 if (!cfg) 4286 4303 return -EINVAL; 4287 4304 4288 - irte_info = &cfg->irq_2_iommu; 4305 + irte_info = &cfg->irq_2_irte; 4289 4306 devid = get_hpet_devid(id); 4290 4307 if (devid < 0) 4291 4308 return devid; ··· 4295 4312 return index; 4296 4313 4297 4314 cfg->remapped = 1; 4298 - irte_info->sub_handle = devid; 4299 - irte_info->irte_index = index; 4315 + irte_info->devid = devid; 4316 + irte_info->index = index; 4300 4317 4301 4318 return 0; 4302 4319 }
+138 -16
drivers/iommu/amd_iommu_init.c
··· 213 213 IOMMU_INIT_ERROR, 214 214 }; 215 215 216 + /* Early ioapic and hpet maps from kernel command line */ 217 + #define EARLY_MAP_SIZE 4 218 + static struct devid_map __initdata early_ioapic_map[EARLY_MAP_SIZE]; 219 + static struct devid_map __initdata early_hpet_map[EARLY_MAP_SIZE]; 220 + static int __initdata early_ioapic_map_size; 221 + static int __initdata early_hpet_map_size; 222 + static bool __initdata cmdline_maps; 223 + 216 224 static enum iommu_init_state init_state = IOMMU_START_STATE; 217 225 218 226 static int amd_iommu_enable_interrupts(void); ··· 711 703 set_iommu_for_device(iommu, devid); 712 704 } 713 705 714 - static int add_special_device(u8 type, u8 id, u16 devid) 706 + static int __init add_special_device(u8 type, u8 id, u16 devid, bool cmd_line) 715 707 { 716 708 struct devid_map *entry; 717 709 struct list_head *list; 718 710 719 - if (type != IVHD_SPECIAL_IOAPIC && type != IVHD_SPECIAL_HPET) 711 + if (type == IVHD_SPECIAL_IOAPIC) 712 + list = &ioapic_map; 713 + else if (type == IVHD_SPECIAL_HPET) 714 + list = &hpet_map; 715 + else 720 716 return -EINVAL; 717 + 718 + list_for_each_entry(entry, list, list) { 719 + if (!(entry->id == id && entry->cmd_line)) 720 + continue; 721 + 722 + pr_info("AMD-Vi: Command-line override present for %s id %d - ignoring\n", 723 + type == IVHD_SPECIAL_IOAPIC ? "IOAPIC" : "HPET", id); 724 + 725 + return 0; 726 + } 721 727 722 728 entry = kzalloc(sizeof(*entry), GFP_KERNEL); 723 729 if (!entry) 724 730 return -ENOMEM; 725 731 726 - entry->id = id; 727 - entry->devid = devid; 728 - 729 - if (type == IVHD_SPECIAL_IOAPIC) 730 - list = &ioapic_map; 731 - else 732 - list = &hpet_map; 732 + entry->id = id; 733 + entry->devid = devid; 734 + entry->cmd_line = cmd_line; 733 735 734 736 list_add_tail(&entry->list, list); 737 + 738 + return 0; 739 + } 740 + 741 + static int __init add_early_maps(void) 742 + { 743 + int i, ret; 744 + 745 + for (i = 0; i < early_ioapic_map_size; ++i) { 746 + ret = add_special_device(IVHD_SPECIAL_IOAPIC, 747 + early_ioapic_map[i].id, 748 + early_ioapic_map[i].devid, 749 + early_ioapic_map[i].cmd_line); 750 + if (ret) 751 + return ret; 752 + } 753 + 754 + for (i = 0; i < early_hpet_map_size; ++i) { 755 + ret = add_special_device(IVHD_SPECIAL_HPET, 756 + early_hpet_map[i].id, 757 + early_hpet_map[i].devid, 758 + early_hpet_map[i].cmd_line); 759 + if (ret) 760 + return ret; 761 + } 735 762 736 763 return 0; 737 764 } ··· 807 764 u32 dev_i, ext_flags = 0; 808 765 bool alias = false; 809 766 struct ivhd_entry *e; 767 + int ret; 768 + 769 + 770 + ret = add_early_maps(); 771 + if (ret) 772 + return ret; 810 773 811 774 /* 812 775 * First save the recommended feature enable bits from ACPI ··· 978 929 PCI_FUNC(devid)); 979 930 980 931 set_dev_entry_from_acpi(iommu, devid, e->flags, 0); 981 - ret = add_special_device(type, handle, devid); 932 + ret = add_special_device(type, handle, devid, false); 982 933 if (ret) 983 934 return ret; 984 935 break; ··· 1324 1275 amd_iommu_int_handler, 1325 1276 amd_iommu_int_thread, 1326 1277 0, "AMD-Vi", 1327 - iommu->dev); 1278 + iommu); 1328 1279 1329 1280 if (r) { 1330 1281 pci_disable_msi(iommu->dev); ··· 1687 1638 1688 1639 static bool __init check_ioapic_information(void) 1689 1640 { 1641 + const char *fw_bug = FW_BUG; 1690 1642 bool ret, has_sb_ioapic; 1691 1643 int idx; 1692 1644 1693 1645 has_sb_ioapic = false; 1694 1646 ret = false; 1695 1647 1648 + /* 1649 + * If we have map overrides on the kernel command line the 1650 + * messages in this function might not describe firmware bugs 1651 + * anymore - so be careful 1652 + */ 1653 + if (cmdline_maps) 1654 + fw_bug = ""; 1655 + 1696 1656 for (idx = 0; idx < nr_ioapics; idx++) { 1697 1657 int devid, id = mpc_ioapic_id(idx); 1698 1658 1699 1659 devid = get_ioapic_devid(id); 1700 1660 if (devid < 0) { 1701 - pr_err(FW_BUG "AMD-Vi: IOAPIC[%d] not in IVRS table\n", id); 1661 + pr_err("%sAMD-Vi: IOAPIC[%d] not in IVRS table\n", 1662 + fw_bug, id); 1702 1663 ret = false; 1703 1664 } else if (devid == IOAPIC_SB_DEVID) { 1704 1665 has_sb_ioapic = true; ··· 1725 1666 * when the BIOS is buggy and provides us the wrong 1726 1667 * device id for the IOAPIC in the system. 1727 1668 */ 1728 - pr_err(FW_BUG "AMD-Vi: No southbridge IOAPIC found in IVRS table\n"); 1669 + pr_err("%sAMD-Vi: No southbridge IOAPIC found\n", fw_bug); 1729 1670 } 1730 1671 1731 1672 if (!ret) 1732 - pr_err("AMD-Vi: Disabling interrupt remapping due to BIOS Bug(s)\n"); 1673 + pr_err("AMD-Vi: Disabling interrupt remapping\n"); 1733 1674 1734 1675 return ret; 1735 1676 } ··· 1860 1801 * Interrupt remapping enabled, create kmem_cache for the 1861 1802 * remapping tables. 1862 1803 */ 1804 + ret = -ENOMEM; 1863 1805 amd_iommu_irq_cache = kmem_cache_create("irq_remap_cache", 1864 1806 MAX_IRQS_PER_TABLE * sizeof(u32), 1865 1807 IRQ_TABLE_ALIGNMENT, ··· 2157 2097 return 1; 2158 2098 } 2159 2099 2160 - __setup("amd_iommu_dump", parse_amd_iommu_dump); 2161 - __setup("amd_iommu=", parse_amd_iommu_options); 2100 + static int __init parse_ivrs_ioapic(char *str) 2101 + { 2102 + unsigned int bus, dev, fn; 2103 + int ret, id, i; 2104 + u16 devid; 2105 + 2106 + ret = sscanf(str, "[%d]=%x:%x.%x", &id, &bus, &dev, &fn); 2107 + 2108 + if (ret != 4) { 2109 + pr_err("AMD-Vi: Invalid command line: ivrs_ioapic%s\n", str); 2110 + return 1; 2111 + } 2112 + 2113 + if (early_ioapic_map_size == EARLY_MAP_SIZE) { 2114 + pr_err("AMD-Vi: Early IOAPIC map overflow - ignoring ivrs_ioapic%s\n", 2115 + str); 2116 + return 1; 2117 + } 2118 + 2119 + devid = ((bus & 0xff) << 8) | ((dev & 0x1f) << 3) | (fn & 0x7); 2120 + 2121 + cmdline_maps = true; 2122 + i = early_ioapic_map_size++; 2123 + early_ioapic_map[i].id = id; 2124 + early_ioapic_map[i].devid = devid; 2125 + early_ioapic_map[i].cmd_line = true; 2126 + 2127 + return 1; 2128 + } 2129 + 2130 + static int __init parse_ivrs_hpet(char *str) 2131 + { 2132 + unsigned int bus, dev, fn; 2133 + int ret, id, i; 2134 + u16 devid; 2135 + 2136 + ret = sscanf(str, "[%d]=%x:%x.%x", &id, &bus, &dev, &fn); 2137 + 2138 + if (ret != 4) { 2139 + pr_err("AMD-Vi: Invalid command line: ivrs_hpet%s\n", str); 2140 + return 1; 2141 + } 2142 + 2143 + if (early_hpet_map_size == EARLY_MAP_SIZE) { 2144 + pr_err("AMD-Vi: Early HPET map overflow - ignoring ivrs_hpet%s\n", 2145 + str); 2146 + return 1; 2147 + } 2148 + 2149 + devid = ((bus & 0xff) << 8) | ((dev & 0x1f) << 3) | (fn & 0x7); 2150 + 2151 + cmdline_maps = true; 2152 + i = early_hpet_map_size++; 2153 + early_hpet_map[i].id = id; 2154 + early_hpet_map[i].devid = devid; 2155 + early_hpet_map[i].cmd_line = true; 2156 + 2157 + return 1; 2158 + } 2159 + 2160 + __setup("amd_iommu_dump", parse_amd_iommu_dump); 2161 + __setup("amd_iommu=", parse_amd_iommu_options); 2162 + __setup("ivrs_ioapic", parse_ivrs_ioapic); 2163 + __setup("ivrs_hpet", parse_ivrs_hpet); 2162 2164 2163 2165 IOMMU_INIT_FINISH(amd_iommu_detect, 2164 2166 gart_iommu_hole_init,
+2
drivers/iommu/amd_iommu_types.h
··· 100 100 #define PASID_MASK 0x000fffff 101 101 102 102 /* MMIO status bits */ 103 + #define MMIO_STATUS_EVT_INT_MASK (1 << 1) 103 104 #define MMIO_STATUS_COM_WAIT_INT_MASK (1 << 2) 104 105 #define MMIO_STATUS_PPR_INT_MASK (1 << 6) 105 106 ··· 590 589 struct list_head list; 591 590 u8 id; 592 591 u16 devid; 592 + bool cmd_line; 593 593 }; 594 594 595 595 /* Map HPET and IOAPIC ids to the devid used by the IOMMU */
+17 -6
drivers/iommu/dmar.c
··· 646 646 int alloc_iommu(struct dmar_drhd_unit *drhd) 647 647 { 648 648 struct intel_iommu *iommu; 649 - u32 ver; 649 + u32 ver, sts; 650 650 static int iommu_allocated = 0; 651 651 int agaw = 0; 652 652 int msagaw = 0; ··· 695 695 DMAR_VER_MAJOR(ver), DMAR_VER_MINOR(ver), 696 696 (unsigned long long)iommu->cap, 697 697 (unsigned long long)iommu->ecap); 698 + 699 + /* Reflect status in gcmd */ 700 + sts = readl(iommu->reg + DMAR_GSTS_REG); 701 + if (sts & DMA_GSTS_IRES) 702 + iommu->gcmd |= DMA_GCMD_IRE; 703 + if (sts & DMA_GSTS_TES) 704 + iommu->gcmd |= DMA_GCMD_TE; 705 + if (sts & DMA_GSTS_QIES) 706 + iommu->gcmd |= DMA_GCMD_QIE; 698 707 699 708 raw_spin_lock_init(&iommu->register_lock); 700 709 ··· 1214 1205 1215 1206 /* TBD: ignore advanced fault log currently */ 1216 1207 if (!(fault_status & DMA_FSTS_PPF)) 1217 - goto clear_rest; 1208 + goto unlock_exit; 1218 1209 1219 1210 fault_index = dma_fsts_fault_record_index(fault_status); 1220 1211 reg = cap_fault_reg_offset(iommu->cap); ··· 1255 1246 fault_index = 0; 1256 1247 raw_spin_lock_irqsave(&iommu->register_lock, flag); 1257 1248 } 1258 - clear_rest: 1259 - /* clear all the other faults */ 1260 - fault_status = readl(iommu->reg + DMAR_FSTS_REG); 1261 - writel(fault_status, iommu->reg + DMAR_FSTS_REG); 1262 1249 1250 + writel(DMA_FSTS_PFO | DMA_FSTS_PPF, iommu->reg + DMAR_FSTS_REG); 1251 + 1252 + unlock_exit: 1263 1253 raw_spin_unlock_irqrestore(&iommu->register_lock, flag); 1264 1254 return IRQ_HANDLED; 1265 1255 } ··· 1306 1298 for_each_drhd_unit(drhd) { 1307 1299 int ret; 1308 1300 struct intel_iommu *iommu = drhd->iommu; 1301 + u32 fault_status; 1309 1302 ret = dmar_set_interrupt(iommu); 1310 1303 1311 1304 if (ret) { ··· 1319 1310 * Clear any previous faults. 1320 1311 */ 1321 1312 dmar_fault(iommu->irq, iommu); 1313 + fault_status = readl(iommu->reg + DMAR_FSTS_REG); 1314 + writel(fault_status, iommu->reg + DMAR_FSTS_REG); 1322 1315 } 1323 1316 1324 1317 return 0;
+1 -1
drivers/iommu/exynos-iommu.c
··· 1027 1027 } 1028 1028 1029 1029 static phys_addr_t exynos_iommu_iova_to_phys(struct iommu_domain *domain, 1030 - unsigned long iova) 1030 + dma_addr_t iova) 1031 1031 { 1032 1032 struct exynos_iommu_domain *priv = domain->priv; 1033 1033 unsigned long *entry;
+17 -7
drivers/iommu/intel-iommu.c
··· 47 47 #include <asm/iommu.h> 48 48 49 49 #include "irq_remapping.h" 50 + #include "pci.h" 50 51 51 52 #define ROOT_SIZE VTD_PAGE_SIZE 52 53 #define CONTEXT_SIZE VTD_PAGE_SIZE ··· 3666 3665 int __init intel_iommu_init(void) 3667 3666 { 3668 3667 int ret = 0; 3668 + struct dmar_drhd_unit *drhd; 3669 3669 3670 3670 /* VT-d is required for a TXT/tboot launch, so enforce that */ 3671 3671 force_on = tboot_force_iommu(); ··· 3675 3673 if (force_on) 3676 3674 panic("tboot: Failed to initialize DMAR table\n"); 3677 3675 return -ENODEV; 3676 + } 3677 + 3678 + /* 3679 + * Disable translation if already enabled prior to OS handover. 3680 + */ 3681 + for_each_drhd_unit(drhd) { 3682 + struct intel_iommu *iommu; 3683 + 3684 + if (drhd->ignored) 3685 + continue; 3686 + 3687 + iommu = drhd->iommu; 3688 + if (iommu->gcmd & DMA_GCMD_TE) 3689 + iommu_disable_translation(iommu); 3678 3690 } 3679 3691 3680 3692 if (dmar_dev_scope_init() < 0) { ··· 4127 4111 } 4128 4112 4129 4113 static phys_addr_t intel_iommu_iova_to_phys(struct iommu_domain *domain, 4130 - unsigned long iova) 4114 + dma_addr_t iova) 4131 4115 { 4132 4116 struct dmar_domain *dmar_domain = domain->priv; 4133 4117 struct dma_pte *pte; ··· 4151 4135 return irq_remapping_enabled; 4152 4136 4153 4137 return 0; 4154 - } 4155 - 4156 - static void swap_pci_ref(struct pci_dev **from, struct pci_dev *to) 4157 - { 4158 - pci_dev_put(*from); 4159 - *from = to; 4160 4138 } 4161 4139 4162 4140 #define REQ_ACS_FLAGS (PCI_ACS_SV | PCI_ACS_RR | PCI_ACS_CR | PCI_ACS_UF)
+10
drivers/iommu/intel_irq_remapping.c
··· 524 524 525 525 if (disable_irq_remap) 526 526 return 0; 527 + if (irq_remap_broken) { 528 + WARN_TAINT(1, TAINT_FIRMWARE_WORKAROUND, 529 + "This system BIOS has enabled interrupt remapping\n" 530 + "on a chipset that contains an erratum making that\n" 531 + "feature unstable. To maintain system stability\n" 532 + "interrupt remapping is being disabled. Please\n" 533 + "contact your BIOS vendor for an update\n"); 534 + disable_irq_remap = 1; 535 + return 0; 536 + } 527 537 528 538 if (!dmar_ir_support()) 529 539 return 0;
+33 -4
drivers/iommu/iommu.c
··· 204 204 } 205 205 EXPORT_SYMBOL_GPL(iommu_group_alloc); 206 206 207 + struct iommu_group *iommu_group_get_by_id(int id) 208 + { 209 + struct kobject *group_kobj; 210 + struct iommu_group *group; 211 + const char *name; 212 + 213 + if (!iommu_group_kset) 214 + return NULL; 215 + 216 + name = kasprintf(GFP_KERNEL, "%d", id); 217 + if (!name) 218 + return NULL; 219 + 220 + group_kobj = kset_find_obj(iommu_group_kset, name); 221 + kfree(name); 222 + 223 + if (!group_kobj) 224 + return NULL; 225 + 226 + group = container_of(group_kobj, struct iommu_group, kobj); 227 + BUG_ON(group->id != id); 228 + 229 + kobject_get(group->devices_kobj); 230 + kobject_put(&group->kobj); 231 + 232 + return group; 233 + } 234 + EXPORT_SYMBOL_GPL(iommu_group_get_by_id); 235 + 207 236 /** 208 237 * iommu_group_get_iommudata - retrieve iommu_data registered for a group 209 238 * @group: the group ··· 735 706 } 736 707 EXPORT_SYMBOL_GPL(iommu_detach_group); 737 708 738 - phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain, 739 - unsigned long iova) 709 + phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain, dma_addr_t iova) 740 710 { 741 711 if (unlikely(domain->ops->iova_to_phys == NULL)) 742 712 return 0; ··· 882 854 883 855 884 856 int iommu_domain_window_enable(struct iommu_domain *domain, u32 wnd_nr, 885 - phys_addr_t paddr, u64 size) 857 + phys_addr_t paddr, u64 size, int prot) 886 858 { 887 859 if (unlikely(domain->ops->domain_window_enable == NULL)) 888 860 return -ENODEV; 889 861 890 - return domain->ops->domain_window_enable(domain, wnd_nr, paddr, size); 862 + return domain->ops->domain_window_enable(domain, wnd_nr, paddr, size, 863 + prot); 891 864 } 892 865 EXPORT_SYMBOL_GPL(iommu_domain_window_enable); 893 866
+6
drivers/iommu/irq_remapping.c
··· 18 18 int irq_remapping_enabled; 19 19 20 20 int disable_irq_remap; 21 + int irq_remap_broken; 21 22 int disable_sourceid_checking; 22 23 int no_x2apic_optout; 23 24 ··· 209 208 if (amd_iommu_irq_ops.prepare() == 0) 210 209 remap_ops = &amd_iommu_irq_ops; 211 210 #endif 211 + } 212 + 213 + void set_irq_remapping_broken(void) 214 + { 215 + irq_remap_broken = 1; 212 216 } 213 217 214 218 int irq_remapping_supported(void)
+2
drivers/iommu/irq_remapping.h
··· 32 32 struct msi_msg; 33 33 34 34 extern int disable_irq_remap; 35 + extern int irq_remap_broken; 35 36 extern int disable_sourceid_checking; 36 37 extern int no_x2apic_optout; 37 38 extern int irq_remapping_enabled; ··· 90 89 91 90 #define irq_remapping_enabled 0 92 91 #define disable_irq_remap 1 92 + #define irq_remap_broken 0 93 93 94 94 #endif /* CONFIG_IRQ_REMAP */ 95 95
+1 -1
drivers/iommu/msm_iommu.c
··· 554 554 } 555 555 556 556 static phys_addr_t msm_iommu_iova_to_phys(struct iommu_domain *domain, 557 - unsigned long va) 557 + dma_addr_t va) 558 558 { 559 559 struct msm_priv *priv; 560 560 struct msm_iommu_drvdata *iommu_drvdata;
+1 -1
drivers/iommu/omap-iommu.c
··· 1219 1219 } 1220 1220 1221 1221 static phys_addr_t omap_iommu_iova_to_phys(struct iommu_domain *domain, 1222 - unsigned long da) 1222 + dma_addr_t da) 1223 1223 { 1224 1224 struct omap_iommu_domain *omap_domain = domain->priv; 1225 1225 struct omap_iommu *oiommu = omap_domain->iommu_dev;
+29
drivers/iommu/pci.h
··· 1 + /* 2 + * This program is free software; you can redistribute it and/or modify 3 + * it under the terms of the GNU General Public License, version 2, as 4 + * published by the Free Software Foundation. 5 + * 6 + * This program is distributed in the hope that it will be useful, 7 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 8 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 9 + * GNU General Public License for more details. 10 + * 11 + * You should have received a copy of the GNU General Public License 12 + * along with this program; if not, write to the Free Software 13 + * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 14 + * 15 + * Copyright (C) 2013 Red Hat, Inc. 16 + * Copyright (C) 2013 Freescale Semiconductor, Inc. 17 + * 18 + */ 19 + #ifndef __IOMMU_PCI_H 20 + #define __IOMMU_PCI_H 21 + 22 + /* Helper function for swapping pci device reference */ 23 + static inline void swap_pci_ref(struct pci_dev **from, struct pci_dev *to) 24 + { 25 + pci_dev_put(*from); 26 + *from = to; 27 + } 28 + 29 + #endif /* __IOMMU_PCI_H */
+1 -1
drivers/iommu/shmobile-iommu.c
··· 296 296 } 297 297 298 298 static phys_addr_t shmobile_iommu_iova_to_phys(struct iommu_domain *domain, 299 - unsigned long iova) 299 + dma_addr_t iova) 300 300 { 301 301 struct shmobile_iommu_domain *sh_domain = domain->priv; 302 302 uint32_t l1entry = 0, l2entry = 0;
+3 -2
drivers/iommu/tegra-gart.c
··· 279 279 } 280 280 281 281 static phys_addr_t gart_iommu_iova_to_phys(struct iommu_domain *domain, 282 - unsigned long iova) 282 + dma_addr_t iova) 283 283 { 284 284 struct gart_device *gart = domain->priv; 285 285 unsigned long pte; ··· 295 295 296 296 pa = (pte & GART_PAGE_MASK); 297 297 if (!pfn_valid(__phys_to_pfn(pa))) { 298 - dev_err(gart->dev, "No entry for %08lx:%08x\n", iova, pa); 298 + dev_err(gart->dev, "No entry for %08llx:%08x\n", 299 + (unsigned long long)iova, pa); 299 300 gart_dump_table(gart); 300 301 return -EINVAL; 301 302 }
+3 -2
drivers/iommu/tegra-smmu.c
··· 757 757 } 758 758 759 759 static phys_addr_t smmu_iommu_iova_to_phys(struct iommu_domain *domain, 760 - unsigned long iova) 760 + dma_addr_t iova) 761 761 { 762 762 struct smmu_as *as = domain->priv; 763 763 unsigned long *pte; ··· 772 772 pfn = *pte & SMMU_PFN_MASK; 773 773 WARN_ON(!pfn_valid(pfn)); 774 774 dev_dbg(as->smmu->dev, 775 - "iova:%08lx pfn:%08lx asid:%d\n", iova, pfn, as->asid); 775 + "iova:%08llx pfn:%08lx asid:%d\n", (unsigned long long)iova, 776 + pfn, as->asid); 776 777 777 778 spin_unlock_irqrestore(&as->lock, flags); 778 779 return PFN_PHYS(pfn);
+9 -9
include/linux/iommu.h
··· 20 20 #define __LINUX_IOMMU_H 21 21 22 22 #include <linux/errno.h> 23 + #include <linux/err.h> 23 24 #include <linux/types.h> 24 25 25 26 #define IOMMU_READ (1) ··· 92 91 phys_addr_t paddr, size_t size, int prot); 93 92 size_t (*unmap)(struct iommu_domain *domain, unsigned long iova, 94 93 size_t size); 95 - phys_addr_t (*iova_to_phys)(struct iommu_domain *domain, 96 - unsigned long iova); 94 + phys_addr_t (*iova_to_phys)(struct iommu_domain *domain, dma_addr_t iova); 97 95 int (*domain_has_cap)(struct iommu_domain *domain, 98 96 unsigned long cap); 99 97 int (*add_device)(struct device *dev); ··· 105 105 106 106 /* Window handling functions */ 107 107 int (*domain_window_enable)(struct iommu_domain *domain, u32 wnd_nr, 108 - phys_addr_t paddr, u64 size); 108 + phys_addr_t paddr, u64 size, int prot); 109 109 void (*domain_window_disable)(struct iommu_domain *domain, u32 wnd_nr); 110 110 /* Set the numer of window per domain */ 111 111 int (*domain_set_windows)(struct iommu_domain *domain, u32 w_count); ··· 125 125 extern int bus_set_iommu(struct bus_type *bus, struct iommu_ops *ops); 126 126 extern bool iommu_present(struct bus_type *bus); 127 127 extern struct iommu_domain *iommu_domain_alloc(struct bus_type *bus); 128 + extern struct iommu_group *iommu_group_get_by_id(int id); 128 129 extern void iommu_domain_free(struct iommu_domain *domain); 129 130 extern int iommu_attach_device(struct iommu_domain *domain, 130 131 struct device *dev); ··· 135 134 phys_addr_t paddr, size_t size, int prot); 136 135 extern size_t iommu_unmap(struct iommu_domain *domain, unsigned long iova, 137 136 size_t size); 138 - extern phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain, 139 - unsigned long iova); 137 + extern phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain, dma_addr_t iova); 140 138 extern int iommu_domain_has_cap(struct iommu_domain *domain, 141 139 unsigned long cap); 142 140 extern void iommu_set_fault_handler(struct iommu_domain *domain, ··· 171 171 172 172 /* Window handling function prototypes */ 173 173 extern int iommu_domain_window_enable(struct iommu_domain *domain, u32 wnd_nr, 174 - phys_addr_t offset, u64 size); 174 + phys_addr_t offset, u64 size, 175 + int prot); 175 176 extern void iommu_domain_window_disable(struct iommu_domain *domain, u32 wnd_nr); 176 177 /** 177 178 * report_iommu_fault() - report about an IOMMU fault to the IOMMU framework ··· 258 257 259 258 static inline int iommu_domain_window_enable(struct iommu_domain *domain, 260 259 u32 wnd_nr, phys_addr_t paddr, 261 - u64 size) 260 + u64 size, int prot) 262 261 { 263 262 return -ENODEV; 264 263 } ··· 268 267 { 269 268 } 270 269 271 - static inline phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain, 272 - unsigned long iova) 270 + static inline phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain, dma_addr_t iova) 273 271 { 274 272 return 0; 275 273 }