Dan Williams | 285f5fa | 2006-12-07 02:59:39 +0100 | [diff] [blame] | 1 | /* |
| 2 | * iop13xx custom ioremap implementation |
| 3 | * Copyright (c) 2005-2006, Intel Corporation. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms and conditions of the GNU General Public License, |
| 7 | * version 2, as published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | * more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along with |
| 15 | * this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
| 16 | * Place - Suite 330, Boston, MA 02111-1307 USA. |
| 17 | * |
| 18 | */ |
| 19 | #include <linux/kernel.h> |
| 20 | #include <linux/module.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 21 | #include <linux/io.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 22 | #include <mach/hardware.h> |
Dan Williams | 285f5fa | 2006-12-07 02:59:39 +0100 | [diff] [blame] | 23 | |
Rob Herring | 17d971e | 2012-02-29 10:58:05 -0600 | [diff] [blame^] | 24 | #include "pci.h" |
| 25 | |
Dan Williams | b0b1d60 | 2006-12-29 01:30:24 +0100 | [diff] [blame] | 26 | void * __iomem __iop13xx_io(unsigned long io_addr) |
| 27 | { |
| 28 | void __iomem * io_virt; |
| 29 | |
| 30 | switch (io_addr) { |
| 31 | case IOP13XX_PCIE_LOWER_IO_PA ... IOP13XX_PCIE_UPPER_IO_PA: |
| 32 | io_virt = (void *) IOP13XX_PCIE_IO_PHYS_TO_VIRT(io_addr); |
| 33 | break; |
| 34 | case IOP13XX_PCIX_LOWER_IO_PA ... IOP13XX_PCIX_UPPER_IO_PA: |
| 35 | io_virt = (void *) IOP13XX_PCIX_IO_PHYS_TO_VIRT(io_addr); |
| 36 | break; |
| 37 | default: |
| 38 | BUG(); |
| 39 | } |
| 40 | |
| 41 | return io_virt; |
| 42 | } |
| 43 | EXPORT_SYMBOL(__iop13xx_io); |
| 44 | |
Rob Herring | 1dfe34a | 2012-02-29 10:56:15 -0600 | [diff] [blame] | 45 | static void __iomem *__iop13xx_ioremap_caller(unsigned long cookie, |
| 46 | size_t size, unsigned int mtype, void *caller) |
Dan Williams | 285f5fa | 2006-12-07 02:59:39 +0100 | [diff] [blame] | 47 | { |
| 48 | void __iomem * retval; |
| 49 | |
| 50 | switch (cookie) { |
| 51 | case IOP13XX_PCIX_LOWER_MEM_RA ... IOP13XX_PCIX_UPPER_MEM_RA: |
| 52 | if (unlikely(!iop13xx_atux_mem_base)) |
| 53 | retval = NULL; |
| 54 | else |
| 55 | retval = (void *)(iop13xx_atux_mem_base + |
| 56 | (cookie - IOP13XX_PCIX_LOWER_MEM_RA)); |
| 57 | break; |
| 58 | case IOP13XX_PCIE_LOWER_MEM_RA ... IOP13XX_PCIE_UPPER_MEM_RA: |
| 59 | if (unlikely(!iop13xx_atue_mem_base)) |
| 60 | retval = NULL; |
| 61 | else |
| 62 | retval = (void *)(iop13xx_atue_mem_base + |
| 63 | (cookie - IOP13XX_PCIE_LOWER_MEM_RA)); |
| 64 | break; |
| 65 | case IOP13XX_PBI_LOWER_MEM_RA ... IOP13XX_PBI_UPPER_MEM_RA: |
Russell King | 31aa8fd | 2009-12-18 11:10:03 +0000 | [diff] [blame] | 66 | retval = __arm_ioremap_caller(IOP13XX_PBI_LOWER_MEM_PA + |
Russell King | 3603ab2 | 2007-05-05 20:59:27 +0100 | [diff] [blame] | 67 | (cookie - IOP13XX_PBI_LOWER_MEM_RA), |
Russell King | 31aa8fd | 2009-12-18 11:10:03 +0000 | [diff] [blame] | 68 | size, mtype, __builtin_return_address(0)); |
Dan Williams | 285f5fa | 2006-12-07 02:59:39 +0100 | [diff] [blame] | 69 | break; |
| 70 | case IOP13XX_PCIE_LOWER_IO_PA ... IOP13XX_PCIE_UPPER_IO_PA: |
| 71 | retval = (void *) IOP13XX_PCIE_IO_PHYS_TO_VIRT(cookie); |
| 72 | break; |
| 73 | case IOP13XX_PCIX_LOWER_IO_PA ... IOP13XX_PCIX_UPPER_IO_PA: |
| 74 | retval = (void *) IOP13XX_PCIX_IO_PHYS_TO_VIRT(cookie); |
| 75 | break; |
| 76 | case IOP13XX_PMMR_PHYS_MEM_BASE ... IOP13XX_PMMR_UPPER_MEM_PA: |
| 77 | retval = (void *) IOP13XX_PMMR_PHYS_TO_VIRT(cookie); |
| 78 | break; |
| 79 | default: |
Russell King | 31aa8fd | 2009-12-18 11:10:03 +0000 | [diff] [blame] | 80 | retval = __arm_ioremap_caller(cookie, size, mtype, |
Rob Herring | 1dfe34a | 2012-02-29 10:56:15 -0600 | [diff] [blame] | 81 | caller); |
Dan Williams | 285f5fa | 2006-12-07 02:59:39 +0100 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | return retval; |
| 85 | } |
Dan Williams | 285f5fa | 2006-12-07 02:59:39 +0100 | [diff] [blame] | 86 | |
Rob Herring | 1dfe34a | 2012-02-29 10:56:15 -0600 | [diff] [blame] | 87 | static void __iop13xx_iounmap(volatile void __iomem *addr) |
Dan Williams | 285f5fa | 2006-12-07 02:59:39 +0100 | [diff] [blame] | 88 | { |
Dan Williams | 285f5fa | 2006-12-07 02:59:39 +0100 | [diff] [blame] | 89 | if (iop13xx_atue_mem_base) |
| 90 | if (addr >= (void __iomem *) iop13xx_atue_mem_base && |
| 91 | addr < (void __iomem *) (iop13xx_atue_mem_base + |
| 92 | iop13xx_atue_mem_size)) |
| 93 | goto skip; |
| 94 | |
| 95 | if (iop13xx_atux_mem_base) |
| 96 | if (addr >= (void __iomem *) iop13xx_atux_mem_base && |
| 97 | addr < (void __iomem *) (iop13xx_atux_mem_base + |
| 98 | iop13xx_atux_mem_size)) |
| 99 | goto skip; |
| 100 | |
| 101 | switch ((u32) addr) { |
| 102 | case IOP13XX_PCIE_LOWER_IO_VA ... IOP13XX_PCIE_UPPER_IO_VA: |
| 103 | case IOP13XX_PCIX_LOWER_IO_VA ... IOP13XX_PCIX_UPPER_IO_VA: |
| 104 | case IOP13XX_PMMR_VIRT_MEM_BASE ... IOP13XX_PMMR_UPPER_MEM_VA: |
| 105 | goto skip; |
| 106 | } |
| 107 | __iounmap(addr); |
| 108 | |
| 109 | skip: |
| 110 | return; |
| 111 | } |
Rob Herring | 1dfe34a | 2012-02-29 10:56:15 -0600 | [diff] [blame] | 112 | |
| 113 | void __init iop13xx_init_early(void) |
| 114 | { |
| 115 | arch_ioremap_caller = __iop13xx_ioremap_caller; |
| 116 | arch_iounmap = __iop13xx_iounmap; |
| 117 | } |