1 From 739029f49bd9181b821298f9d27b29ce2d292967 Mon Sep 17 00:00:00 2001
2 From: Yangbo Lu <yangbo.lu@nxp.com>
3 Date: Mon, 25 Sep 2017 10:03:52 +0800
4 Subject: [PATCH] arch: support layerscape
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 This is a integrated patch for layerscape arch support.
11 Signed-off-by: Madalin Bucur <madalin.bucur@nxp.com>
12 Signed-off-by: Nipun Gupta <nipun.gupta@nxp.com>
13 Signed-off-by: Zhao Qiang <B45475@freescale.com>
14 Signed-off-by: Camelia Groza <camelia.groza@nxp.com>
15 Signed-off-by: Haiying Wang <Haiying.wang@freescale.com>
16 Signed-off-by: Pan Jiafei <Jiafei.Pan@nxp.com>
17 Signed-off-by: Po Liu <po.liu@nxp.com>
18 Signed-off-by: Bharat Bhushan <Bharat.Bhushan@nxp.com>
19 Signed-off-by: Jianhua Xie <jianhua.xie@nxp.com>
20 Signed-off-by: Horia Geantă <horia.geanta@nxp.com>
21 Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
23 arch/arm/include/asm/delay.h | 16 +++++++++
24 arch/arm/include/asm/io.h | 31 ++++++++++++++++++
25 arch/arm/include/asm/mach/map.h | 4 +--
26 arch/arm/include/asm/pgtable.h | 7 ++++
27 arch/arm/kernel/bios32.c | 43 ++++++++++++++++++++++++
28 arch/arm/mm/dma-mapping.c | 1 +
29 arch/arm/mm/ioremap.c | 7 ++++
30 arch/arm/mm/mmu.c | 9 +++++
31 arch/arm64/include/asm/cache.h | 2 +-
32 arch/arm64/include/asm/io.h | 2 ++
33 arch/arm64/include/asm/pci.h | 4 +++
34 arch/arm64/include/asm/pgtable-prot.h | 1 +
35 arch/arm64/include/asm/pgtable.h | 5 +++
36 arch/arm64/kernel/pci.c | 62 +++++++++++++++++++++++++++++++++++
37 arch/arm64/mm/dma-mapping.c | 23 ++++++++++---
38 15 files changed, 209 insertions(+), 8 deletions(-)
40 --- a/arch/arm/include/asm/delay.h
41 +++ b/arch/arm/include/asm/delay.h
42 @@ -57,6 +57,22 @@ extern void __bad_udelay(void);
43 __const_udelay((n) * UDELAY_MULT)) : \
46 +#define spin_event_timeout(condition, timeout, delay) \
48 + typeof(condition) __ret; \
50 + while (!(__ret = (condition)) && (i++ < timeout)) { \
58 + __ret = (condition); \
62 /* Loop-based definitions for assembly code. */
63 extern void __loop_delay(unsigned long loops);
64 extern void __loop_udelay(unsigned long usecs);
65 --- a/arch/arm/include/asm/io.h
66 +++ b/arch/arm/include/asm/io.h
67 @@ -129,6 +129,7 @@ static inline u32 __raw_readl(const vola
68 #define MT_DEVICE_NONSHARED 1
69 #define MT_DEVICE_CACHED 2
70 #define MT_DEVICE_WC 3
71 +#define MT_MEMORY_RW_NS 4
73 * types 4 onwards can be found in asm/mach/map.h and are undefined
75 @@ -220,6 +221,34 @@ extern int pci_ioremap_io(unsigned int o
80 +#define setbits32(_addr, _v) iowrite32be(ioread32be(_addr) | (_v), (_addr))
81 +#define clrbits32(_addr, _v) iowrite32be(ioread32be(_addr) & ~(_v), (_addr))
83 +#define setbits16(_addr, _v) iowrite16be(ioread16be(_addr) | (_v), (_addr))
84 +#define clrbits16(_addr, _v) iowrite16be(ioread16be(_addr) & ~(_v), (_addr))
86 +#define setbits8(_addr, _v) iowrite8(ioread8(_addr) | (_v), (_addr))
87 +#define clrbits8(_addr, _v) iowrite8(ioread8(_addr) & ~(_v), (_addr))
89 +/* Clear and set bits in one shot. These macros can be used to clear and
90 + * set multiple bits in a register using a single read-modify-write. These
91 + * macros can also be used to set a multiple-bit bit pattern using a mask,
92 + * by specifying the mask in the 'clear' parameter and the new bit pattern
93 + * in the 'set' parameter.
96 +#define clrsetbits_be32(addr, clear, set) \
97 + iowrite32be((ioread32be(addr) & ~(clear)) | (set), (addr))
98 +#define clrsetbits_le32(addr, clear, set) \
99 + iowrite32le((ioread32le(addr) & ~(clear)) | (set), (addr))
100 +#define clrsetbits_be16(addr, clear, set) \
101 + iowrite16be((ioread16be(addr) & ~(clear)) | (set), (addr))
102 +#define clrsetbits_le16(addr, clear, set) \
103 + iowrite16le((ioread16le(addr) & ~(clear)) | (set), (addr))
104 +#define clrsetbits_8(addr, clear, set) \
105 + iowrite8((ioread8(addr) & ~(clear)) | (set), (addr))
108 * IO port access primitives
109 * -------------------------
110 @@ -408,6 +437,8 @@ void __iomem *ioremap_wc(resource_size_t
111 #define ioremap_wc ioremap_wc
112 #define ioremap_wt ioremap_wc
114 +void __iomem *ioremap_cache_ns(resource_size_t res_cookie, size_t size);
116 void iounmap(volatile void __iomem *iomem_cookie);
117 #define iounmap iounmap
119 --- a/arch/arm/include/asm/mach/map.h
120 +++ b/arch/arm/include/asm/mach/map.h
121 @@ -21,9 +21,9 @@ struct map_desc {
125 -/* types 0-3 are defined in asm/io.h */
126 +/* types 0-4 are defined in asm/io.h */
133 --- a/arch/arm/include/asm/pgtable.h
134 +++ b/arch/arm/include/asm/pgtable.h
135 @@ -118,6 +118,13 @@ extern pgprot_t pgprot_s2_device;
136 #define pgprot_noncached(prot) \
137 __pgprot_modify(prot, L_PTE_MT_MASK, L_PTE_MT_UNCACHED)
139 +#define pgprot_cached(prot) \
140 + __pgprot_modify(prot, L_PTE_MT_MASK, L_PTE_MT_DEV_CACHED)
142 +#define pgprot_cached_ns(prot) \
143 + __pgprot_modify(prot, L_PTE_MT_MASK, L_PTE_MT_DEV_CACHED | \
144 + L_PTE_MT_DEV_NONSHARED)
146 #define pgprot_writecombine(prot) \
147 __pgprot_modify(prot, L_PTE_MT_MASK, L_PTE_MT_BUFFERABLE)
149 --- a/arch/arm/kernel/bios32.c
150 +++ b/arch/arm/kernel/bios32.c
152 #include <linux/slab.h>
153 #include <linux/init.h>
154 #include <linux/io.h>
155 +#include <linux/of_irq.h>
156 +#include <linux/pcieport_if.h>
158 #include <asm/mach-types.h>
159 #include <asm/mach/map.h>
160 @@ -64,6 +66,47 @@ void pcibios_report_status(u_int status_
164 + * Check device tree if the service interrupts are there
166 +int pcibios_check_service_irqs(struct pci_dev *dev, int *irqs, int mask)
168 + int ret, count = 0;
169 + struct device_node *np = NULL;
171 + if (dev->bus->dev.of_node)
172 + np = dev->bus->dev.of_node;
177 + if (!IS_ENABLED(CONFIG_OF_IRQ))
180 + /* If root port doesn't support MSI/MSI-X/INTx in RC mode,
181 + * request irq for aer
183 + if (mask & PCIE_PORT_SERVICE_AER) {
184 + ret = of_irq_get_byname(np, "aer");
186 + irqs[PCIE_PORT_SERVICE_AER_SHIFT] = ret;
191 + if (mask & PCIE_PORT_SERVICE_PME) {
192 + ret = of_irq_get_byname(np, "pme");
194 + irqs[PCIE_PORT_SERVICE_PME_SHIFT] = ret;
199 + /* TODO: add more service interrupts if there it is in the device tree*/
205 * We don't use this to fix the device, but initialisation of it.
206 * It's not the correct use for this, but it works.
207 * Note that the arbiter/ISA bridge appears to be buggy, specifically in
208 --- a/arch/arm/mm/dma-mapping.c
209 +++ b/arch/arm/mm/dma-mapping.c
210 @@ -2392,6 +2392,7 @@ void arch_setup_dma_ops(struct device *d
212 set_dma_ops(dev, dma_ops);
214 +EXPORT_SYMBOL(arch_setup_dma_ops);
216 void arch_teardown_dma_ops(struct device *dev)
218 --- a/arch/arm/mm/ioremap.c
219 +++ b/arch/arm/mm/ioremap.c
220 @@ -398,6 +398,13 @@ void __iomem *ioremap_wc(resource_size_t
222 EXPORT_SYMBOL(ioremap_wc);
224 +void __iomem *ioremap_cache_ns(resource_size_t res_cookie, size_t size)
226 + return arch_ioremap_caller(res_cookie, size, MT_MEMORY_RW_NS,
227 + __builtin_return_address(0));
229 +EXPORT_SYMBOL(ioremap_cache_ns);
232 * Remap an arbitrary physical address space into the kernel virtual
233 * address space as memory. Needed when the kernel wants to execute
234 --- a/arch/arm/mm/mmu.c
235 +++ b/arch/arm/mm/mmu.c
236 @@ -313,6 +313,13 @@ static struct mem_type mem_types[] __ro_
237 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
238 .domain = DOMAIN_KERNEL,
240 + [MT_MEMORY_RW_NS] = {
241 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
243 + .prot_l1 = PMD_TYPE_TABLE,
244 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_XN,
245 + .domain = DOMAIN_KERNEL,
248 .prot_sect = PMD_TYPE_SECT,
249 .domain = DOMAIN_KERNEL,
250 @@ -644,6 +651,7 @@ static void __init build_mem_type_table(
252 kern_pgprot |= PTE_EXT_AF;
253 vecs_pgprot |= PTE_EXT_AF;
254 + mem_types[MT_MEMORY_RW_NS].prot_pte |= PTE_EXT_AF | cp->pte;
257 * Set PXN for user mappings
258 @@ -672,6 +680,7 @@ static void __init build_mem_type_table(
259 mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
260 mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
261 mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
262 + mem_types[MT_MEMORY_RW_NS].prot_sect |= ecc_mask | cp->pmd;
263 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
264 mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= ecc_mask;
265 mem_types[MT_ROM].prot_sect |= cp->pmd;
266 --- a/arch/arm64/include/asm/cache.h
267 +++ b/arch/arm64/include/asm/cache.h
270 #include <asm/cachetype.h>
272 -#define L1_CACHE_SHIFT 7
273 +#define L1_CACHE_SHIFT 6
274 #define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
277 --- a/arch/arm64/include/asm/io.h
278 +++ b/arch/arm64/include/asm/io.h
279 @@ -171,6 +171,8 @@ extern void __iomem *ioremap_cache(phys_
280 #define ioremap_nocache(addr, size) __ioremap((addr), (size), __pgprot(PROT_DEVICE_nGnRE))
281 #define ioremap_wc(addr, size) __ioremap((addr), (size), __pgprot(PROT_NORMAL_NC))
282 #define ioremap_wt(addr, size) __ioremap((addr), (size), __pgprot(PROT_DEVICE_nGnRE))
283 +#define ioremap_cache_ns(addr, size) __ioremap((addr), (size), \
284 + __pgprot(PROT_NORMAL_NS))
285 #define iounmap __iounmap
288 --- a/arch/arm64/include/asm/pci.h
289 +++ b/arch/arm64/include/asm/pci.h
290 @@ -31,6 +31,10 @@ static inline int pci_get_legacy_ide_irq
294 +#define HAVE_PCI_MMAP
295 +extern int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
296 + enum pci_mmap_state mmap_state,
297 + int write_combine);
298 static inline int pci_proc_domain(struct pci_bus *bus)
301 --- a/arch/arm64/include/asm/pgtable-prot.h
302 +++ b/arch/arm64/include/asm/pgtable-prot.h
304 #define PROT_NORMAL_NC (PROT_DEFAULT | PTE_PXN | PTE_UXN | PTE_DIRTY | PTE_WRITE | PTE_ATTRINDX(MT_NORMAL_NC))
305 #define PROT_NORMAL_WT (PROT_DEFAULT | PTE_PXN | PTE_UXN | PTE_DIRTY | PTE_WRITE | PTE_ATTRINDX(MT_NORMAL_WT))
306 #define PROT_NORMAL (PROT_DEFAULT | PTE_PXN | PTE_UXN | PTE_DIRTY | PTE_WRITE | PTE_ATTRINDX(MT_NORMAL))
307 +#define PROT_NORMAL_NS (PTE_TYPE_PAGE | PTE_AF | PTE_PXN | PTE_UXN | PTE_DIRTY | PTE_WRITE | PTE_ATTRINDX(MT_NORMAL))
309 #define PROT_SECT_DEVICE_nGnRE (PROT_SECT_DEFAULT | PMD_SECT_PXN | PMD_SECT_UXN | PMD_ATTRINDX(MT_DEVICE_nGnRE))
310 #define PROT_SECT_NORMAL (PROT_SECT_DEFAULT | PMD_SECT_PXN | PMD_SECT_UXN | PMD_ATTRINDX(MT_NORMAL))
311 --- a/arch/arm64/include/asm/pgtable.h
312 +++ b/arch/arm64/include/asm/pgtable.h
313 @@ -370,6 +370,11 @@ static inline int pmd_protnone(pmd_t pmd
314 __pgprot_modify(prot, PTE_ATTRINDX_MASK, PTE_ATTRINDX(MT_DEVICE_nGnRnE) | PTE_PXN | PTE_UXN)
315 #define pgprot_writecombine(prot) \
316 __pgprot_modify(prot, PTE_ATTRINDX_MASK, PTE_ATTRINDX(MT_NORMAL_NC) | PTE_PXN | PTE_UXN)
317 +#define pgprot_cached(prot) \
318 + __pgprot_modify(prot, PTE_ATTRINDX_MASK, PTE_ATTRINDX(MT_NORMAL) | \
320 +#define pgprot_cached_ns(prot) \
321 + __pgprot(pgprot_val(pgprot_cached(prot)) ^ PTE_SHARED)
322 #define pgprot_device(prot) \
323 __pgprot_modify(prot, PTE_ATTRINDX_MASK, PTE_ATTRINDX(MT_DEVICE_nGnRE) | PTE_PXN | PTE_UXN)
324 #define __HAVE_PHYS_MEM_ACCESS_PROT
325 --- a/arch/arm64/kernel/pci.c
326 +++ b/arch/arm64/kernel/pci.c
328 #include <linux/mm.h>
329 #include <linux/of_pci.h>
330 #include <linux/of_platform.h>
331 +#include <linux/of_irq.h>
332 +#include <linux/pcieport_if.h>
333 #include <linux/pci.h>
334 #include <linux/pci-acpi.h>
335 #include <linux/pci-ecam.h>
336 @@ -53,6 +55,66 @@ int pcibios_alloc_irq(struct pci_dev *de
342 + * Check device tree if the service interrupts are there
344 +int pcibios_check_service_irqs(struct pci_dev *dev, int *irqs, int mask)
346 + int ret, count = 0;
347 + struct device_node *np = NULL;
349 + if (dev->bus->dev.of_node)
350 + np = dev->bus->dev.of_node;
355 + if (!IS_ENABLED(CONFIG_OF_IRQ))
358 + /* If root port doesn't support MSI/MSI-X/INTx in RC mode,
359 + * request irq for aer
361 + if (mask & PCIE_PORT_SERVICE_AER) {
362 + ret = of_irq_get_byname(np, "aer");
364 + irqs[PCIE_PORT_SERVICE_AER_SHIFT] = ret;
369 + if (mask & PCIE_PORT_SERVICE_PME) {
370 + ret = of_irq_get_byname(np, "pme");
372 + irqs[PCIE_PORT_SERVICE_PME_SHIFT] = ret;
377 + /* TODO: add more service interrupts if there it is in the device tree*/
382 +int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
383 + enum pci_mmap_state mmap_state, int write_combine)
385 + if (mmap_state == pci_mmap_io)
391 + vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
393 + if (remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
394 + vma->vm_end - vma->vm_start,
395 + vma->vm_page_prot))
402 * raw_pci_read/write - Platform-specific PCI config space access.
403 --- a/arch/arm64/mm/dma-mapping.c
404 +++ b/arch/arm64/mm/dma-mapping.c
406 #include <linux/swiotlb.h>
408 #include <asm/cacheflush.h>
409 +#include <../../../drivers/staging/fsl-mc/include/mc-bus.h>
411 static int swiotlb __ro_after_init;
413 @@ -925,6 +926,10 @@ static int __init __iommu_dma_init(void)
415 ret = register_iommu_dma_ops_notifier(&pci_bus_type);
417 +#ifdef CONFIG_FSL_MC_BUS
419 + ret = register_iommu_dma_ops_notifier(&fsl_mc_bus_type);
423 arch_initcall(__iommu_dma_init);
424 @@ -978,3 +983,4 @@ void arch_setup_dma_ops(struct device *d
425 dev->archdata.dma_coherent = coherent;
426 __iommu_setup_dma_ops(dev, dma_base, size, iommu);
428 +EXPORT_SYMBOL(arch_setup_dma_ops);