Merge branch 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6-microblaze.git] / drivers / iommu / amd_iommu.c
index b0b30a5..0cea80b 100644 (file)
@@ -354,6 +354,9 @@ static bool pci_iommuv2_capable(struct pci_dev *pdev)
        };
        int i, pos;
 
+       if (pci_ats_disabled())
+               return false;
+
        for (i = 0; i < 3; ++i) {
                pos = pci_find_ext_capability(pdev, caps[i]);
                if (pos == 0)
@@ -544,7 +547,7 @@ static void amd_iommu_report_page_fault(u16 devid, u16 domain_id,
 static void iommu_print_event(struct amd_iommu *iommu, void *__evt)
 {
        struct device *dev = iommu->iommu.dev;
-       int type, devid, domid, flags;
+       int type, devid, pasid, flags, tag;
        volatile u32 *event = __evt;
        int count = 0;
        u64 address;
@@ -552,7 +555,7 @@ static void iommu_print_event(struct amd_iommu *iommu, void *__evt)
 retry:
        type    = (event[1] >> EVENT_TYPE_SHIFT)  & EVENT_TYPE_MASK;
        devid   = (event[0] >> EVENT_DEVID_SHIFT) & EVENT_DEVID_MASK;
-       domid   = (event[1] >> EVENT_DOMID_SHIFT) & EVENT_DOMID_MASK;
+       pasid   = PPR_PASID(*(u64 *)&event[0]);
        flags   = (event[1] >> EVENT_FLAGS_SHIFT) & EVENT_FLAGS_MASK;
        address = (u64)(((u64)event[3]) << 32) | event[2];
 
@@ -567,7 +570,7 @@ retry:
        }
 
        if (type == EVENT_TYPE_IO_FAULT) {
-               amd_iommu_report_page_fault(devid, domid, address, flags);
+               amd_iommu_report_page_fault(devid, pasid, address, flags);
                return;
        } else {
                dev_err(dev, "AMD-Vi: Event logged [");
@@ -575,10 +578,9 @@ retry:
 
        switch (type) {
        case EVENT_TYPE_ILL_DEV:
-               dev_err(dev, "ILLEGAL_DEV_TABLE_ENTRY device=%02x:%02x.%x "
-                       "address=0x%016llx flags=0x%04x]\n",
+               dev_err(dev, "ILLEGAL_DEV_TABLE_ENTRY device=%02x:%02x.%x pasid=0x%05x address=0x%016llx flags=0x%04x]\n",
                        PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid),
-                       address, flags);
+                       pasid, address, flags);
                dump_dte_entry(devid);
                break;
        case EVENT_TYPE_DEV_TAB_ERR:
@@ -588,34 +590,38 @@ retry:
                        address, flags);
                break;
        case EVENT_TYPE_PAGE_TAB_ERR:
-               dev_err(dev, "PAGE_TAB_HARDWARE_ERROR device=%02x:%02x.%x "
-                       "domain=0x%04x address=0x%016llx flags=0x%04x]\n",
+               dev_err(dev, "PAGE_TAB_HARDWARE_ERROR device=%02x:%02x.%x domain=0x%04x address=0x%016llx flags=0x%04x]\n",
                        PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid),
-                       domid, address, flags);
+                       pasid, address, flags);
                break;
        case EVENT_TYPE_ILL_CMD:
                dev_err(dev, "ILLEGAL_COMMAND_ERROR address=0x%016llx]\n", address);
                dump_command(address);
                break;
        case EVENT_TYPE_CMD_HARD_ERR:
-               dev_err(dev, "COMMAND_HARDWARE_ERROR address=0x%016llx "
-                       "flags=0x%04x]\n", address, flags);
+               dev_err(dev, "COMMAND_HARDWARE_ERROR address=0x%016llx flags=0x%04x]\n",
+                       address, flags);
                break;
        case EVENT_TYPE_IOTLB_INV_TO:
-               dev_err(dev, "IOTLB_INV_TIMEOUT device=%02x:%02x.%x "
-                       "address=0x%016llx]\n",
+               dev_err(dev, "IOTLB_INV_TIMEOUT device=%02x:%02x.%x address=0x%016llx]\n",
                        PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid),
                        address);
                break;
        case EVENT_TYPE_INV_DEV_REQ:
-               dev_err(dev, "INVALID_DEVICE_REQUEST device=%02x:%02x.%x "
-                       "address=0x%016llx flags=0x%04x]\n",
+               dev_err(dev, "INVALID_DEVICE_REQUEST device=%02x:%02x.%x pasid=0x%05x address=0x%016llx flags=0x%04x]\n",
                        PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid),
-                       address, flags);
+                       pasid, address, flags);
+               break;
+       case EVENT_TYPE_INV_PPR_REQ:
+               pasid = ((event[0] >> 16) & 0xFFFF)
+                       | ((event[1] << 6) & 0xF0000);
+               tag = event[1] & 0x03FF;
+               dev_err(dev, "INVALID_PPR_REQUEST device=%02x:%02x.%x pasid=0x%05x address=0x%016llx flags=0x%04x]\n",
+                       PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid),
+                       pasid, address, flags);
                break;
        default:
-               dev_err(dev, KERN_ERR "UNKNOWN event[0]=0x%08x event[1]=0x%08x "
-                       "event[2]=0x%08x event[3]=0x%08x\n",
+               dev_err(dev, "UNKNOWN event[0]=0x%08x event[1]=0x%08x event[2]=0x%08x event[3]=0x%08x\n",
                        event[0], event[1], event[2], event[3]);
        }
 
@@ -1911,15 +1917,6 @@ static void do_detach(struct iommu_dev_data *dev_data)
        struct amd_iommu *iommu;
        u16 alias;
 
-       /*
-        * First check if the device is still attached. It might already
-        * be detached from its domain because the generic
-        * iommu_detach_group code detached it and we try again here in
-        * our alias handling.
-        */
-       if (!dev_data->domain)
-               return;
-
        iommu = amd_iommu_rlookup_table[dev_data->devid];
        alias = dev_data->alias;
 
@@ -1939,8 +1936,8 @@ static void do_detach(struct iommu_dev_data *dev_data)
 }
 
 /*
- * If a device is not yet associated with a domain, this function does
- * assigns it visible for the hardware
+ * If a device is not yet associated with a domain, this function makes the
+ * device visible in the domain
  */
 static int __attach_device(struct iommu_dev_data *dev_data,
                           struct protection_domain *domain)
@@ -2061,8 +2058,8 @@ static bool pci_pri_tlp_required(struct pci_dev *pdev)
 }
 
 /*
- * If a device is not yet associated with a domain, this function
- * assigns it visible for the hardware
+ * If a device is not yet associated with a domain, this function makes the
+ * device visible in the domain
  */
 static int attach_device(struct device *dev,
                         struct protection_domain *domain)
@@ -2124,9 +2121,6 @@ static void __detach_device(struct iommu_dev_data *dev_data)
         */
        WARN_ON(!irqs_disabled());
 
-       if (WARN_ON(!dev_data->domain))
-               return;
-
        domain = dev_data->domain;
 
        spin_lock(&domain->lock);
@@ -2148,6 +2142,15 @@ static void detach_device(struct device *dev)
        dev_data = get_dev_data(dev);
        domain   = dev_data->domain;
 
+       /*
+        * First check if the device is still attached. It might already
+        * be detached from its domain because the generic
+        * iommu_detach_group code detached it and we try again here in
+        * our alias handling.
+        */
+       if (WARN_ON(!dev_data->domain))
+               return;
+
        /* lock device table */
        spin_lock_irqsave(&amd_iommu_devtable_lock, flags);
        __detach_device(dev_data);
@@ -2793,6 +2796,7 @@ static void cleanup_domain(struct protection_domain *domain)
        while (!list_empty(&domain->dev_list)) {
                entry = list_first_entry(&domain->dev_list,
                                         struct iommu_dev_data, list);
+               BUG_ON(!entry->domain);
                __detach_device(entry);
        }
 
@@ -3523,9 +3527,11 @@ int amd_iommu_device_info(struct pci_dev *pdev,
 
        memset(info, 0, sizeof(*info));
 
-       pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ATS);
-       if (pos)
-               info->flags |= AMD_IOMMU_DEVICE_FLAG_ATS_SUP;
+       if (!pci_ats_disabled()) {
+               pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ATS);
+               if (pos)
+                       info->flags |= AMD_IOMMU_DEVICE_FLAG_ATS_SUP;
+       }
 
        pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_PRI);
        if (pos)