kernel: bump 5.4 to 5.4.119
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-5.4 / 950-0440-x86-PCI-sta2x11-use-default-DMA-address-translation.patch
1 From 97a48106d1698038720495fdd49c491b283bf110 Mon Sep 17 00:00:00 2001
2 From: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
3 Date: Thu, 7 Nov 2019 16:06:45 +0100
4 Subject: [PATCH] x86/PCI: sta2x11: use default DMA address translation
5
6 commit e380a0394c36a3a878c858418d5dd7f5f195b6fc upstream.
7
8 The devices found behind this PCIe chip have unusual DMA mapping
9 constraints as there is an AMBA interconnect placed in between them and
10 the different PCI endpoints. The offset between physical memory
11 addresses and AMBA's view is provided by reading a PCI config register,
12 which is saved and used whenever DMA mapping is needed.
13
14 It turns out that this DMA setup can be represented by properly setting
15 'dma_pfn_offset', 'dma_bus_mask' and 'dma_mask' during the PCI device
16 enable fixup. And ultimately allows us to get rid of this device's
17 custom DMA functions.
18
19 Aside from the code deletion and DMA setup, sta2x11_pdev_to_mapping() is
20 moved to avoid warnings whenever CONFIG_PM is not enabled.
21
22 Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
23 Signed-off-by: Christoph Hellwig <hch@lst.de>
24 ---
25 arch/x86/Kconfig | 1 -
26 arch/x86/include/asm/device.h | 3 -
27 arch/x86/include/asm/dma-direct.h | 9 --
28 arch/x86/pci/sta2x11-fixup.c | 135 ++++++------------------------
29 4 files changed, 26 insertions(+), 122 deletions(-)
30 delete mode 100644 arch/x86/include/asm/dma-direct.h
31
32 --- a/arch/x86/Kconfig
33 +++ b/arch/x86/Kconfig
34 @@ -709,7 +709,6 @@ config X86_SUPPORTS_MEMORY_FAILURE
35 config STA2X11
36 bool "STA2X11 Companion Chip Support"
37 depends on X86_32_NON_STANDARD && PCI
38 - select ARCH_HAS_PHYS_TO_DMA
39 select SWIOTLB
40 select MFD_STA2X11
41 select GPIOLIB
42 --- a/arch/x86/include/asm/device.h
43 +++ b/arch/x86/include/asm/device.h
44 @@ -6,9 +6,6 @@ struct dev_archdata {
45 #if defined(CONFIG_INTEL_IOMMU) || defined(CONFIG_AMD_IOMMU)
46 void *iommu; /* hook for IOMMU specific extension */
47 #endif
48 -#ifdef CONFIG_STA2X11
49 - bool is_sta2x11;
50 -#endif
51 };
52
53 #if defined(CONFIG_X86_DEV_DMA_OPS) && defined(CONFIG_PCI_DOMAINS)
54 --- a/arch/x86/include/asm/dma-direct.h
55 +++ /dev/null
56 @@ -1,9 +0,0 @@
57 -/* SPDX-License-Identifier: GPL-2.0 */
58 -#ifndef ASM_X86_DMA_DIRECT_H
59 -#define ASM_X86_DMA_DIRECT_H 1
60 -
61 -bool dma_capable(struct device *dev, dma_addr_t addr, size_t size);
62 -dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr);
63 -phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t daddr);
64 -
65 -#endif /* ASM_X86_DMA_DIRECT_H */
66 --- a/arch/x86/pci/sta2x11-fixup.c
67 +++ b/arch/x86/pci/sta2x11-fixup.c
68 @@ -30,7 +30,6 @@ struct sta2x11_ahb_regs { /* saved durin
69 };
70
71 struct sta2x11_mapping {
72 - u32 amba_base;
73 int is_suspended;
74 struct sta2x11_ahb_regs regs[STA2X11_NR_FUNCS];
75 };
76 @@ -92,18 +91,6 @@ static int sta2x11_pdev_to_ep(struct pci
77 return pdev->bus->number - instance->bus0;
78 }
79
80 -static struct sta2x11_mapping *sta2x11_pdev_to_mapping(struct pci_dev *pdev)
81 -{
82 - struct sta2x11_instance *instance;
83 - int ep;
84 -
85 - instance = sta2x11_pdev_to_instance(pdev);
86 - if (!instance)
87 - return NULL;
88 - ep = sta2x11_pdev_to_ep(pdev);
89 - return instance->map + ep;
90 -}
91 -
92 /* This is exported, as some devices need to access the MFD registers */
93 struct sta2x11_instance *sta2x11_get_instance(struct pci_dev *pdev)
94 {
95 @@ -111,39 +98,6 @@ struct sta2x11_instance *sta2x11_get_ins
96 }
97 EXPORT_SYMBOL(sta2x11_get_instance);
98
99 -
100 -/**
101 - * p2a - Translate physical address to STA2x11 AMBA address,
102 - * used for DMA transfers to STA2x11
103 - * @p: Physical address
104 - * @pdev: PCI device (must be hosted within the connext)
105 - */
106 -static dma_addr_t p2a(dma_addr_t p, struct pci_dev *pdev)
107 -{
108 - struct sta2x11_mapping *map;
109 - dma_addr_t a;
110 -
111 - map = sta2x11_pdev_to_mapping(pdev);
112 - a = p + map->amba_base;
113 - return a;
114 -}
115 -
116 -/**
117 - * a2p - Translate STA2x11 AMBA address to physical address
118 - * used for DMA transfers from STA2x11
119 - * @a: STA2x11 AMBA address
120 - * @pdev: PCI device (must be hosted within the connext)
121 - */
122 -static dma_addr_t a2p(dma_addr_t a, struct pci_dev *pdev)
123 -{
124 - struct sta2x11_mapping *map;
125 - dma_addr_t p;
126 -
127 - map = sta2x11_pdev_to_mapping(pdev);
128 - p = a - map->amba_base;
129 - return p;
130 -}
131 -
132 /* At setup time, we use our own ops if the device is a ConneXt one */
133 static void sta2x11_setup_pdev(struct pci_dev *pdev)
134 {
135 @@ -151,9 +105,6 @@ static void sta2x11_setup_pdev(struct pc
136
137 if (!instance) /* either a sta2x11 bridge or another ST device */
138 return;
139 - pci_set_consistent_dma_mask(pdev, STA2X11_AMBA_SIZE - 1);
140 - pci_set_dma_mask(pdev, STA2X11_AMBA_SIZE - 1);
141 - pdev->dev.archdata.is_sta2x11 = true;
142
143 /* We must enable all devices as master, for audio DMA to work */
144 pci_set_master(pdev);
145 @@ -161,61 +112,6 @@ static void sta2x11_setup_pdev(struct pc
146 DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_STMICRO, PCI_ANY_ID, sta2x11_setup_pdev);
147
148 /*
149 - * The following three functions are exported (used in swiotlb: FIXME)
150 - */
151 -/**
152 - * dma_capable - Check if device can manage DMA transfers (FIXME: kill it)
153 - * @dev: device for a PCI device
154 - * @addr: DMA address
155 - * @size: DMA size
156 - */
157 -bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
158 -{
159 - struct sta2x11_mapping *map;
160 -
161 - if (!dev->archdata.is_sta2x11) {
162 - if (!dev->dma_mask)
163 - return false;
164 - return addr + size - 1 <= *dev->dma_mask;
165 - }
166 -
167 - map = sta2x11_pdev_to_mapping(to_pci_dev(dev));
168 -
169 - if (!map || (addr < map->amba_base))
170 - return false;
171 - if (addr + size >= map->amba_base + STA2X11_AMBA_SIZE) {
172 - return false;
173 - }
174 -
175 - return true;
176 -}
177 -
178 -/**
179 - * __phys_to_dma - Return the DMA AMBA address used for this STA2x11 device
180 - * @dev: device for a PCI device
181 - * @paddr: Physical address
182 - */
183 -dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
184 -{
185 - if (!dev->archdata.is_sta2x11)
186 - return paddr;
187 - return p2a(paddr, to_pci_dev(dev));
188 -}
189 -
190 -/**
191 - * dma_to_phys - Return the physical address used for this STA2x11 DMA address
192 - * @dev: device for a PCI device
193 - * @daddr: STA2x11 AMBA DMA address
194 - */
195 -phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t daddr)
196 -{
197 - if (!dev->archdata.is_sta2x11)
198 - return daddr;
199 - return a2p(daddr, to_pci_dev(dev));
200 -}
201 -
202 -
203 -/*
204 * At boot we must set up the mappings for the pcie-to-amba bridge.
205 * It involves device access, and the same happens at suspend/resume time
206 */
207 @@ -234,12 +130,22 @@ phys_addr_t __dma_to_phys(struct device
208 /* At probe time, enable mapping for each endpoint, using the pdev */
209 static void sta2x11_map_ep(struct pci_dev *pdev)
210 {
211 - struct sta2x11_mapping *map = sta2x11_pdev_to_mapping(pdev);
212 + struct sta2x11_instance *instance = sta2x11_pdev_to_instance(pdev);
213 + struct device *dev = &pdev->dev;
214 + u32 amba_base, max_amba_addr;
215 int i;
216
217 - if (!map)
218 + if (!instance)
219 return;
220 - pci_read_config_dword(pdev, AHB_BASE(0), &map->amba_base);
221 +
222 + pci_read_config_dword(pdev, AHB_BASE(0), &amba_base);
223 + max_amba_addr = amba_base + STA2X11_AMBA_SIZE - 1;
224 +
225 + dev->dma_pfn_offset = PFN_DOWN(-amba_base);
226 +
227 + dev->bus_dma_mask = max_amba_addr;
228 + pci_set_consistent_dma_mask(pdev, max_amba_addr);
229 + pci_set_dma_mask(pdev, max_amba_addr);
230
231 /* Configure AHB mapping */
232 pci_write_config_dword(pdev, AHB_PEXLBASE(0), 0);
233 @@ -253,13 +159,24 @@ static void sta2x11_map_ep(struct pci_de
234
235 dev_info(&pdev->dev,
236 "sta2x11: Map EP %i: AMBA address %#8x-%#8x\n",
237 - sta2x11_pdev_to_ep(pdev), map->amba_base,
238 - map->amba_base + STA2X11_AMBA_SIZE - 1);
239 + sta2x11_pdev_to_ep(pdev), amba_base, max_amba_addr);
240 }
241 DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_STMICRO, PCI_ANY_ID, sta2x11_map_ep);
242
243 #ifdef CONFIG_PM /* Some register values must be saved and restored */
244
245 +static struct sta2x11_mapping *sta2x11_pdev_to_mapping(struct pci_dev *pdev)
246 +{
247 + struct sta2x11_instance *instance;
248 + int ep;
249 +
250 + instance = sta2x11_pdev_to_instance(pdev);
251 + if (!instance)
252 + return NULL;
253 + ep = sta2x11_pdev_to_ep(pdev);
254 + return instance->map + ep;
255 +}
256 +
257 static void suspend_mapping(struct pci_dev *pdev)
258 {
259 struct sta2x11_mapping *map = sta2x11_pdev_to_mapping(pdev);