Merge branch 'remotes/lorenzo/pci/dwc'
[linux-2.6-microblaze.git] / drivers / pci / p2pdma.c
index e8e444e..85fc993 100644 (file)
@@ -53,7 +53,7 @@ static ssize_t size_show(struct device *dev, struct device_attribute *attr,
        if (pdev->p2pdma->pool)
                size = gen_pool_size(pdev->p2pdma->pool);
 
-       return snprintf(buf, PAGE_SIZE, "%zd\n", size);
+       return scnprintf(buf, PAGE_SIZE, "%zd\n", size);
 }
 static DEVICE_ATTR_RO(size);
 
@@ -66,7 +66,7 @@ static ssize_t available_show(struct device *dev, struct device_attribute *attr,
        if (pdev->p2pdma->pool)
                avail = gen_pool_avail(pdev->p2pdma->pool);
 
-       return snprintf(buf, PAGE_SIZE, "%zd\n", avail);
+       return scnprintf(buf, PAGE_SIZE, "%zd\n", avail);
 }
 static DEVICE_ATTR_RO(available);
 
@@ -75,8 +75,8 @@ static ssize_t published_show(struct device *dev, struct device_attribute *attr,
 {
        struct pci_dev *pdev = to_pci_dev(dev);
 
-       return snprintf(buf, PAGE_SIZE, "%d\n",
-                       pdev->p2pdma->p2pmem_published);
+       return scnprintf(buf, PAGE_SIZE, "%d\n",
+                        pdev->p2pdma->p2pmem_published);
 }
 static DEVICE_ATTR_RO(published);
 
@@ -253,7 +253,7 @@ static int pci_bridge_has_acs_redir(struct pci_dev *pdev)
        int pos;
        u16 ctrl;
 
-       pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ACS);
+       pos = pdev->acs_cap;
        if (!pos)
                return 0;
 
@@ -273,6 +273,19 @@ static void seq_buf_print_bus_devfn(struct seq_buf *buf, struct pci_dev *pdev)
        seq_buf_printf(buf, "%s;", pci_name(pdev));
 }
 
+static bool cpu_supports_p2pdma(void)
+{
+#ifdef CONFIG_X86
+       struct cpuinfo_x86 *c = &cpu_data(0);
+
+       /* Any AMD CPU whose family ID is Zen or newer supports p2pdma */
+       if (c->x86_vendor == X86_VENDOR_AMD && c->x86 >= 0x17)
+               return true;
+#endif
+
+       return false;
+}
+
 static const struct pci_p2pdma_whitelist_entry {
        unsigned short vendor;
        unsigned short device;
@@ -280,11 +293,6 @@ static const struct pci_p2pdma_whitelist_entry {
                REQ_SAME_HOST_BRIDGE    = 1 << 0,
        } flags;
 } pci_p2pdma_whitelist[] = {
-       /* AMD ZEN */
-       {PCI_VENDOR_ID_AMD,     0x1450, 0},
-       {PCI_VENDOR_ID_AMD,     0x15d0, 0},
-       {PCI_VENDOR_ID_AMD,     0x1630, 0},
-
        /* Intel Xeon E5/Core i7 */
        {PCI_VENDOR_ID_INTEL,   0x3c00, REQ_SAME_HOST_BRIDGE},
        {PCI_VENDOR_ID_INTEL,   0x3c01, REQ_SAME_HOST_BRIDGE},
@@ -473,7 +481,8 @@ upstream_bridge_distance(struct pci_dev *provider, struct pci_dev *client,
                                              acs_redirects, acs_list);
 
        if (map_type == PCI_P2PDMA_MAP_THRU_HOST_BRIDGE) {
-               if (!host_bridge_whitelist(provider, client))
+               if (!cpu_supports_p2pdma() &&
+                   !host_bridge_whitelist(provider, client))
                        map_type = PCI_P2PDMA_MAP_NOT_SUPPORTED;
        }
 
@@ -752,7 +761,7 @@ struct scatterlist *pci_p2pmem_alloc_sgl(struct pci_dev *pdev,
        struct scatterlist *sg;
        void *addr;
 
-       sg = kzalloc(sizeof(*sg), GFP_KERNEL);
+       sg = kmalloc(sizeof(*sg), GFP_KERNEL);
        if (!sg)
                return NULL;