Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/sparc
[sfrench/cifs-2.6.git] / arch / arm / mach-iop13xx / io.c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * iop13xx custom ioremap implementation
4  * Copyright (c) 2005-2006, Intel Corporation.
5  */
6 #include <linux/kernel.h>
7 #include <linux/module.h>
8 #include <linux/io.h>
9 #include <mach/hardware.h>
10
11 #include "pci.h"
12
13 static void __iomem *__iop13xx_ioremap_caller(phys_addr_t cookie,
14         size_t size, unsigned int mtype, void *caller)
15 {
16         void __iomem * retval;
17
18         switch (cookie) {
19         case IOP13XX_PCIX_LOWER_MEM_RA ... IOP13XX_PCIX_UPPER_MEM_RA:
20                 if (unlikely(!iop13xx_atux_mem_base))
21                         retval = NULL;
22                 else
23                         retval = (iop13xx_atux_mem_base +
24                                  (cookie - IOP13XX_PCIX_LOWER_MEM_RA));
25                 break;
26         case IOP13XX_PCIE_LOWER_MEM_RA ... IOP13XX_PCIE_UPPER_MEM_RA:
27                 if (unlikely(!iop13xx_atue_mem_base))
28                         retval = NULL;
29                 else
30                         retval = (iop13xx_atue_mem_base +
31                                  (cookie - IOP13XX_PCIE_LOWER_MEM_RA));
32                 break;
33         case IOP13XX_PBI_LOWER_MEM_RA ... IOP13XX_PBI_UPPER_MEM_RA:
34                 retval = __arm_ioremap_caller(IOP13XX_PBI_LOWER_MEM_PA +
35                                        (cookie - IOP13XX_PBI_LOWER_MEM_RA),
36                                        size, mtype, __builtin_return_address(0));
37                 break;
38         case IOP13XX_PMMR_PHYS_MEM_BASE ... IOP13XX_PMMR_UPPER_MEM_PA:
39                 retval = IOP13XX_PMMR_PHYS_TO_VIRT(cookie);
40                 break;
41         default:
42                 retval = __arm_ioremap_caller(cookie, size, mtype,
43                                 caller);
44         }
45
46         return retval;
47 }
48
49 static void __iop13xx_iounmap(volatile void __iomem *addr)
50 {
51         if (iop13xx_atue_mem_base)
52                 if (addr >= (void __iomem *) iop13xx_atue_mem_base &&
53                     addr < (void __iomem *) (iop13xx_atue_mem_base +
54                                              iop13xx_atue_mem_size))
55                     goto skip;
56
57         if (iop13xx_atux_mem_base)
58                 if (addr >= (void __iomem *) iop13xx_atux_mem_base &&
59                     addr < (void __iomem *) (iop13xx_atux_mem_base +
60                                              iop13xx_atux_mem_size))
61                     goto skip;
62
63         switch ((u32) addr) {
64         case (u32)IOP13XX_PMMR_VIRT_MEM_BASE ... (u32)IOP13XX_PMMR_UPPER_MEM_VA:
65                 goto skip;
66         }
67         __iounmap(addr);
68
69 skip:
70         return;
71 }
72
73 void __init iop13xx_init_early(void)
74 {
75         arch_ioremap_caller = __iop13xx_ioremap_caller;
76         arch_iounmap = __iop13xx_iounmap;
77 }