]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.14/pci-endpoint-use-epc-s-device-in-dma_alloc_coherent-dma_free_coherent.patch
Linux 4.9.166
[thirdparty/kernel/stable-queue.git] / queue-4.14 / pci-endpoint-use-epc-s-device-in-dma_alloc_coherent-dma_free_coherent.patch
1 From b330104fa76df3eae6e199a23791fed5d35f06b4 Mon Sep 17 00:00:00 2001
2 From: Kishon Vijay Abraham I <kishon@ti.com>
3 Date: Thu, 11 Jan 2018 14:00:57 +0530
4 Subject: PCI: endpoint: Use EPC's device in dma_alloc_coherent()/dma_free_coherent()
5
6 From: Kishon Vijay Abraham I <kishon@ti.com>
7
8 commit b330104fa76df3eae6e199a23791fed5d35f06b4 upstream.
9
10 After commit 723288836628 ("of: restrict DMA configuration"),
11 of_dma_configure() doesn't configure the coherent_dma_mask/dma_mask
12 of endpoint function device (since it doesn't have a DT node associated
13 with and hence no dma-ranges property), resulting in
14 dma_alloc_coherent() (used in pci_epf_alloc_space()) to fail.
15
16 Fix it by making dma_alloc_coherent() use EPC's device for allocating
17 memory address.
18
19 Link: http://lkml.kernel.org/r/64d63468-d28f-8fcd-a6f3-cf2a6401c8cb@ti.com
20 Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
21 [lorenzo.pieralisi@arm.com: tweaked commit log]
22 Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
23 Cc: Robin Murphy <robin.murphy@arm.com>
24 Cc: Rob Herring <robh@kernel.org>
25 Cc: Christoph Hellwig <hch@lst.de>
26 Tested-by: Cyrille Pitchen <cyrille.pitchen@free-electrons.com>
27 Tested-by: Niklas Cassel <niklas.cassel@axis.com>
28 Reviewed-by: Robin Murphy <robin.murphy@arm.com>
29 Signed-off-by: Arnd Bergmann <arnd@arndb.de>
30 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
31
32 ---
33 drivers/pci/endpoint/pci-epc-core.c | 10 ----------
34 drivers/pci/endpoint/pci-epf-core.c | 4 ++--
35 2 files changed, 2 insertions(+), 12 deletions(-)
36
37 --- a/drivers/pci/endpoint/pci-epc-core.c
38 +++ b/drivers/pci/endpoint/pci-epc-core.c
39 @@ -18,7 +18,6 @@
40 */
41
42 #include <linux/device.h>
43 -#include <linux/dma-mapping.h>
44 #include <linux/slab.h>
45 #include <linux/module.h>
46 #include <linux/of_device.h>
47 @@ -371,7 +370,6 @@ EXPORT_SYMBOL_GPL(pci_epc_write_header);
48 int pci_epc_add_epf(struct pci_epc *epc, struct pci_epf *epf)
49 {
50 unsigned long flags;
51 - struct device *dev = epc->dev.parent;
52
53 if (epf->epc)
54 return -EBUSY;
55 @@ -383,12 +381,6 @@ int pci_epc_add_epf(struct pci_epc *epc,
56 return -EINVAL;
57
58 epf->epc = epc;
59 - if (dev->of_node) {
60 - of_dma_configure(&epf->dev, dev->of_node);
61 - } else {
62 - dma_set_coherent_mask(&epf->dev, epc->dev.coherent_dma_mask);
63 - epf->dev.dma_mask = epc->dev.dma_mask;
64 - }
65
66 spin_lock_irqsave(&epc->lock, flags);
67 list_add_tail(&epf->list, &epc->pci_epf);
68 @@ -503,9 +495,7 @@ __pci_epc_create(struct device *dev, con
69 INIT_LIST_HEAD(&epc->pci_epf);
70
71 device_initialize(&epc->dev);
72 - dma_set_coherent_mask(&epc->dev, dev->coherent_dma_mask);
73 epc->dev.class = pci_epc_class;
74 - epc->dev.dma_mask = dev->dma_mask;
75 epc->dev.parent = dev;
76 epc->ops = ops;
77
78 --- a/drivers/pci/endpoint/pci-epf-core.c
79 +++ b/drivers/pci/endpoint/pci-epf-core.c
80 @@ -99,7 +99,7 @@ EXPORT_SYMBOL_GPL(pci_epf_bind);
81 */
82 void pci_epf_free_space(struct pci_epf *epf, void *addr, enum pci_barno bar)
83 {
84 - struct device *dev = &epf->dev;
85 + struct device *dev = epf->epc->dev.parent;
86
87 if (!addr)
88 return;
89 @@ -122,7 +122,7 @@ EXPORT_SYMBOL_GPL(pci_epf_free_space);
90 void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar)
91 {
92 void *space;
93 - struct device *dev = &epf->dev;
94 + struct device *dev = epf->epc->dev.parent;
95 dma_addr_t phys_addr;
96
97 if (size < 128)