Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/mach-integrator/pci_v3.c |
| 3 | * |
| 4 | * PCI functions for V3 host PCI bridge |
| 5 | * |
| 6 | * Copyright (C) 1999 ARM Limited |
| 7 | * Copyright (C) 2000-2001 Deep Blue Solutions Ltd |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 22 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/kernel.h> |
| 24 | #include <linux/pci.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <linux/ioport.h> |
| 26 | #include <linux/interrupt.h> |
| 27 | #include <linux/spinlock.h> |
| 28 | #include <linux/init.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 29 | #include <linux/io.h> |
Linus Walleij | 86adc39 | 2013-02-02 23:16:57 +0100 | [diff] [blame] | 30 | #include <linux/platform_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 32 | #include <mach/hardware.h> |
Russell King | a285edc | 2010-01-14 19:59:37 +0000 | [diff] [blame] | 33 | #include <mach/platform.h> |
Linus Walleij | 695436e | 2012-02-26 10:46:48 +0100 | [diff] [blame] | 34 | #include <mach/irqs.h> |
| 35 | |
Alexey Dobriyan | d43c36d | 2009-10-07 17:09:06 +0400 | [diff] [blame] | 36 | #include <asm/signal.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include <asm/mach/pci.h> |
Russell King | c6af66b | 2007-05-17 10:16:55 +0100 | [diff] [blame] | 38 | #include <asm/irq_regs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
Linus Walleij | 207bcf4 | 2013-02-03 00:20:44 +0100 | [diff] [blame^] | 40 | /* |
| 41 | * V3 Local Bus to PCI Bridge definitions |
| 42 | * |
| 43 | * Registers (these are taken from page 129 of the EPC User's Manual Rev 1.04 |
| 44 | * All V3 register names are prefaced by V3_ to avoid clashing with any other |
| 45 | * PCI definitions. Their names match the user's manual. |
| 46 | * |
| 47 | * I'm assuming that I20 is disabled. |
| 48 | * |
| 49 | */ |
| 50 | #define V3_PCI_VENDOR 0x00000000 |
| 51 | #define V3_PCI_DEVICE 0x00000002 |
| 52 | #define V3_PCI_CMD 0x00000004 |
| 53 | #define V3_PCI_STAT 0x00000006 |
| 54 | #define V3_PCI_CC_REV 0x00000008 |
| 55 | #define V3_PCI_HDR_CFG 0x0000000C |
| 56 | #define V3_PCI_IO_BASE 0x00000010 |
| 57 | #define V3_PCI_BASE0 0x00000014 |
| 58 | #define V3_PCI_BASE1 0x00000018 |
| 59 | #define V3_PCI_SUB_VENDOR 0x0000002C |
| 60 | #define V3_PCI_SUB_ID 0x0000002E |
| 61 | #define V3_PCI_ROM 0x00000030 |
| 62 | #define V3_PCI_BPARAM 0x0000003C |
| 63 | #define V3_PCI_MAP0 0x00000040 |
| 64 | #define V3_PCI_MAP1 0x00000044 |
| 65 | #define V3_PCI_INT_STAT 0x00000048 |
| 66 | #define V3_PCI_INT_CFG 0x0000004C |
| 67 | #define V3_LB_BASE0 0x00000054 |
| 68 | #define V3_LB_BASE1 0x00000058 |
| 69 | #define V3_LB_MAP0 0x0000005E |
| 70 | #define V3_LB_MAP1 0x00000062 |
| 71 | #define V3_LB_BASE2 0x00000064 |
| 72 | #define V3_LB_MAP2 0x00000066 |
| 73 | #define V3_LB_SIZE 0x00000068 |
| 74 | #define V3_LB_IO_BASE 0x0000006E |
| 75 | #define V3_FIFO_CFG 0x00000070 |
| 76 | #define V3_FIFO_PRIORITY 0x00000072 |
| 77 | #define V3_FIFO_STAT 0x00000074 |
| 78 | #define V3_LB_ISTAT 0x00000076 |
| 79 | #define V3_LB_IMASK 0x00000077 |
| 80 | #define V3_SYSTEM 0x00000078 |
| 81 | #define V3_LB_CFG 0x0000007A |
| 82 | #define V3_PCI_CFG 0x0000007C |
| 83 | #define V3_DMA_PCI_ADR0 0x00000080 |
| 84 | #define V3_DMA_PCI_ADR1 0x00000090 |
| 85 | #define V3_DMA_LOCAL_ADR0 0x00000084 |
| 86 | #define V3_DMA_LOCAL_ADR1 0x00000094 |
| 87 | #define V3_DMA_LENGTH0 0x00000088 |
| 88 | #define V3_DMA_LENGTH1 0x00000098 |
| 89 | #define V3_DMA_CSR0 0x0000008B |
| 90 | #define V3_DMA_CSR1 0x0000009B |
| 91 | #define V3_DMA_CTLB_ADR0 0x0000008C |
| 92 | #define V3_DMA_CTLB_ADR1 0x0000009C |
| 93 | #define V3_DMA_DELAY 0x000000E0 |
| 94 | #define V3_MAIL_DATA 0x000000C0 |
| 95 | #define V3_PCI_MAIL_IEWR 0x000000D0 |
| 96 | #define V3_PCI_MAIL_IERD 0x000000D2 |
| 97 | #define V3_LB_MAIL_IEWR 0x000000D4 |
| 98 | #define V3_LB_MAIL_IERD 0x000000D6 |
| 99 | #define V3_MAIL_WR_STAT 0x000000D8 |
| 100 | #define V3_MAIL_RD_STAT 0x000000DA |
| 101 | #define V3_QBA_MAP 0x000000DC |
| 102 | |
| 103 | /* PCI COMMAND REGISTER bits |
| 104 | */ |
| 105 | #define V3_COMMAND_M_FBB_EN (1 << 9) |
| 106 | #define V3_COMMAND_M_SERR_EN (1 << 8) |
| 107 | #define V3_COMMAND_M_PAR_EN (1 << 6) |
| 108 | #define V3_COMMAND_M_MASTER_EN (1 << 2) |
| 109 | #define V3_COMMAND_M_MEM_EN (1 << 1) |
| 110 | #define V3_COMMAND_M_IO_EN (1 << 0) |
| 111 | |
| 112 | /* SYSTEM REGISTER bits |
| 113 | */ |
| 114 | #define V3_SYSTEM_M_RST_OUT (1 << 15) |
| 115 | #define V3_SYSTEM_M_LOCK (1 << 14) |
| 116 | |
| 117 | /* PCI_CFG bits |
| 118 | */ |
| 119 | #define V3_PCI_CFG_M_I2O_EN (1 << 15) |
| 120 | #define V3_PCI_CFG_M_IO_REG_DIS (1 << 14) |
| 121 | #define V3_PCI_CFG_M_IO_DIS (1 << 13) |
| 122 | #define V3_PCI_CFG_M_EN3V (1 << 12) |
| 123 | #define V3_PCI_CFG_M_RETRY_EN (1 << 10) |
| 124 | #define V3_PCI_CFG_M_AD_LOW1 (1 << 9) |
| 125 | #define V3_PCI_CFG_M_AD_LOW0 (1 << 8) |
| 126 | |
| 127 | /* PCI_BASE register bits (PCI -> Local Bus) |
| 128 | */ |
| 129 | #define V3_PCI_BASE_M_ADR_BASE 0xFFF00000 |
| 130 | #define V3_PCI_BASE_M_ADR_BASEL 0x000FFF00 |
| 131 | #define V3_PCI_BASE_M_PREFETCH (1 << 3) |
| 132 | #define V3_PCI_BASE_M_TYPE (3 << 1) |
| 133 | #define V3_PCI_BASE_M_IO (1 << 0) |
| 134 | |
| 135 | /* PCI MAP register bits (PCI -> Local bus) |
| 136 | */ |
| 137 | #define V3_PCI_MAP_M_MAP_ADR 0xFFF00000 |
| 138 | #define V3_PCI_MAP_M_RD_POST_INH (1 << 15) |
| 139 | #define V3_PCI_MAP_M_ROM_SIZE (3 << 10) |
| 140 | #define V3_PCI_MAP_M_SWAP (3 << 8) |
| 141 | #define V3_PCI_MAP_M_ADR_SIZE 0x000000F0 |
| 142 | #define V3_PCI_MAP_M_REG_EN (1 << 1) |
| 143 | #define V3_PCI_MAP_M_ENABLE (1 << 0) |
| 144 | |
| 145 | /* |
| 146 | * LB_BASE0,1 register bits (Local bus -> PCI) |
| 147 | */ |
| 148 | #define V3_LB_BASE_ADR_BASE 0xfff00000 |
| 149 | #define V3_LB_BASE_SWAP (3 << 8) |
| 150 | #define V3_LB_BASE_ADR_SIZE (15 << 4) |
| 151 | #define V3_LB_BASE_PREFETCH (1 << 3) |
| 152 | #define V3_LB_BASE_ENABLE (1 << 0) |
| 153 | |
| 154 | #define V3_LB_BASE_ADR_SIZE_1MB (0 << 4) |
| 155 | #define V3_LB_BASE_ADR_SIZE_2MB (1 << 4) |
| 156 | #define V3_LB_BASE_ADR_SIZE_4MB (2 << 4) |
| 157 | #define V3_LB_BASE_ADR_SIZE_8MB (3 << 4) |
| 158 | #define V3_LB_BASE_ADR_SIZE_16MB (4 << 4) |
| 159 | #define V3_LB_BASE_ADR_SIZE_32MB (5 << 4) |
| 160 | #define V3_LB_BASE_ADR_SIZE_64MB (6 << 4) |
| 161 | #define V3_LB_BASE_ADR_SIZE_128MB (7 << 4) |
| 162 | #define V3_LB_BASE_ADR_SIZE_256MB (8 << 4) |
| 163 | #define V3_LB_BASE_ADR_SIZE_512MB (9 << 4) |
| 164 | #define V3_LB_BASE_ADR_SIZE_1GB (10 << 4) |
| 165 | #define V3_LB_BASE_ADR_SIZE_2GB (11 << 4) |
| 166 | |
| 167 | #define v3_addr_to_lb_base(a) ((a) & V3_LB_BASE_ADR_BASE) |
| 168 | |
| 169 | /* |
| 170 | * LB_MAP0,1 register bits (Local bus -> PCI) |
| 171 | */ |
| 172 | #define V3_LB_MAP_MAP_ADR 0xfff0 |
| 173 | #define V3_LB_MAP_TYPE (7 << 1) |
| 174 | #define V3_LB_MAP_AD_LOW_EN (1 << 0) |
| 175 | |
| 176 | #define V3_LB_MAP_TYPE_IACK (0 << 1) |
| 177 | #define V3_LB_MAP_TYPE_IO (1 << 1) |
| 178 | #define V3_LB_MAP_TYPE_MEM (3 << 1) |
| 179 | #define V3_LB_MAP_TYPE_CONFIG (5 << 1) |
| 180 | #define V3_LB_MAP_TYPE_MEM_MULTIPLE (6 << 1) |
| 181 | |
| 182 | #define v3_addr_to_lb_map(a) (((a) >> 16) & V3_LB_MAP_MAP_ADR) |
| 183 | |
| 184 | /* |
| 185 | * LB_BASE2 register bits (Local bus -> PCI IO) |
| 186 | */ |
| 187 | #define V3_LB_BASE2_ADR_BASE 0xff00 |
| 188 | #define V3_LB_BASE2_SWAP (3 << 6) |
| 189 | #define V3_LB_BASE2_ENABLE (1 << 0) |
| 190 | |
| 191 | #define v3_addr_to_lb_base2(a) (((a) >> 16) & V3_LB_BASE2_ADR_BASE) |
| 192 | |
| 193 | /* |
| 194 | * LB_MAP2 register bits (Local bus -> PCI IO) |
| 195 | */ |
| 196 | #define V3_LB_MAP2_MAP_ADR 0xff00 |
| 197 | |
| 198 | #define v3_addr_to_lb_map2(a) (((a) >> 16) & V3_LB_MAP2_MAP_ADR) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | |
| 200 | /* |
| 201 | * The V3 PCI interface chip in Integrator provides several windows from |
| 202 | * local bus memory into the PCI memory areas. Unfortunately, there |
Rob Herring | 29d3960 | 2012-07-13 16:27:43 -0500 | [diff] [blame] | 203 | * are not really enough windows for our usage, therefore we reuse |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | * one of the windows for access to PCI configuration space. The |
| 205 | * memory map is as follows: |
Rob Herring | 29d3960 | 2012-07-13 16:27:43 -0500 | [diff] [blame] | 206 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | * Local Bus Memory Usage |
Rob Herring | 29d3960 | 2012-07-13 16:27:43 -0500 | [diff] [blame] | 208 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | * 40000000 - 4FFFFFFF PCI memory. 256M non-prefetchable |
| 210 | * 50000000 - 5FFFFFFF PCI memory. 256M prefetchable |
| 211 | * 60000000 - 60FFFFFF PCI IO. 16M |
| 212 | * 61000000 - 61FFFFFF PCI Configuration. 16M |
Rob Herring | 29d3960 | 2012-07-13 16:27:43 -0500 | [diff] [blame] | 213 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | * There are three V3 windows, each described by a pair of V3 registers. |
| 215 | * These are LB_BASE0/LB_MAP0, LB_BASE1/LB_MAP1 and LB_BASE2/LB_MAP2. |
| 216 | * Base0 and Base1 can be used for any type of PCI memory access. Base2 |
| 217 | * can be used either for PCI I/O or for I20 accesses. By default, uHAL |
| 218 | * uses this only for PCI IO space. |
Rob Herring | 29d3960 | 2012-07-13 16:27:43 -0500 | [diff] [blame] | 219 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | * Normally these spaces are mapped using the following base registers: |
Rob Herring | 29d3960 | 2012-07-13 16:27:43 -0500 | [diff] [blame] | 221 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | * Usage Local Bus Memory Base/Map registers used |
Rob Herring | 29d3960 | 2012-07-13 16:27:43 -0500 | [diff] [blame] | 223 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | * Mem 40000000 - 4FFFFFFF LB_BASE0/LB_MAP0 |
| 225 | * Mem 50000000 - 5FFFFFFF LB_BASE1/LB_MAP1 |
| 226 | * IO 60000000 - 60FFFFFF LB_BASE2/LB_MAP2 |
| 227 | * Cfg 61000000 - 61FFFFFF |
Rob Herring | 29d3960 | 2012-07-13 16:27:43 -0500 | [diff] [blame] | 228 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | * This means that I20 and PCI configuration space accesses will fail. |
Rob Herring | 29d3960 | 2012-07-13 16:27:43 -0500 | [diff] [blame] | 230 | * When PCI configuration accesses are needed (via the uHAL PCI |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | * configuration space primitives) we must remap the spaces as follows: |
Rob Herring | 29d3960 | 2012-07-13 16:27:43 -0500 | [diff] [blame] | 232 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | * Usage Local Bus Memory Base/Map registers used |
Rob Herring | 29d3960 | 2012-07-13 16:27:43 -0500 | [diff] [blame] | 234 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | * Mem 40000000 - 4FFFFFFF LB_BASE0/LB_MAP0 |
| 236 | * Mem 50000000 - 5FFFFFFF LB_BASE0/LB_MAP0 |
| 237 | * IO 60000000 - 60FFFFFF LB_BASE2/LB_MAP2 |
| 238 | * Cfg 61000000 - 61FFFFFF LB_BASE1/LB_MAP1 |
Rob Herring | 29d3960 | 2012-07-13 16:27:43 -0500 | [diff] [blame] | 239 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | * To make this work, the code depends on overlapping windows working. |
Rob Herring | 29d3960 | 2012-07-13 16:27:43 -0500 | [diff] [blame] | 241 | * The V3 chip translates an address by checking its range within |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | * each of the BASE/MAP pairs in turn (in ascending register number |
| 243 | * order). It will use the first matching pair. So, for example, |
| 244 | * if the same address is mapped by both LB_BASE0/LB_MAP0 and |
Rob Herring | 29d3960 | 2012-07-13 16:27:43 -0500 | [diff] [blame] | 245 | * LB_BASE1/LB_MAP1, the V3 will use the translation from |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | * LB_BASE0/LB_MAP0. |
Rob Herring | 29d3960 | 2012-07-13 16:27:43 -0500 | [diff] [blame] | 247 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | * To allow PCI Configuration space access, the code enlarges the |
| 249 | * window mapped by LB_BASE0/LB_MAP0 from 256M to 512M. This occludes |
| 250 | * the windows currently mapped by LB_BASE1/LB_MAP1 so that it can |
| 251 | * be remapped for use by configuration cycles. |
Rob Herring | 29d3960 | 2012-07-13 16:27:43 -0500 | [diff] [blame] | 252 | * |
| 253 | * At the end of the PCI Configuration space accesses, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | * LB_BASE1/LB_MAP1 is reset to map PCI Memory. Finally the window |
| 255 | * mapped by LB_BASE0/LB_MAP0 is reduced in size from 512M to 256M to |
| 256 | * reveal the now restored LB_BASE1/LB_MAP1 window. |
Rob Herring | 29d3960 | 2012-07-13 16:27:43 -0500 | [diff] [blame] | 257 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | * NOTE: We do not set up I2O mapping. I suspect that this is only |
| 259 | * for an intelligent (target) device. Using I2O disables most of |
| 260 | * the mappings into PCI memory. |
| 261 | */ |
| 262 | |
| 263 | // V3 access routines |
| 264 | #define v3_writeb(o,v) __raw_writeb(v, PCI_V3_VADDR + (unsigned int)(o)) |
| 265 | #define v3_readb(o) (__raw_readb(PCI_V3_VADDR + (unsigned int)(o))) |
| 266 | |
| 267 | #define v3_writew(o,v) __raw_writew(v, PCI_V3_VADDR + (unsigned int)(o)) |
| 268 | #define v3_readw(o) (__raw_readw(PCI_V3_VADDR + (unsigned int)(o))) |
| 269 | |
| 270 | #define v3_writel(o,v) __raw_writel(v, PCI_V3_VADDR + (unsigned int)(o)) |
| 271 | #define v3_readl(o) (__raw_readl(PCI_V3_VADDR + (unsigned int)(o))) |
| 272 | |
| 273 | /*============================================================================ |
| 274 | * |
| 275 | * routine: uHALir_PCIMakeConfigAddress() |
| 276 | * |
| 277 | * parameters: bus = which bus |
| 278 | * device = which device |
| 279 | * function = which function |
| 280 | * offset = configuration space register we are interested in |
| 281 | * |
| 282 | * description: this routine will generate a platform dependent config |
| 283 | * address. |
| 284 | * |
| 285 | * calls: none |
| 286 | * |
| 287 | * returns: configuration address to play on the PCI bus |
| 288 | * |
Rob Herring | 29d3960 | 2012-07-13 16:27:43 -0500 | [diff] [blame] | 289 | * To generate the appropriate PCI configuration cycles in the PCI |
| 290 | * configuration address space, you present the V3 with the following pattern |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | * (which is very nearly a type 1 (except that the lower two bits are 00 and |
| 292 | * not 01). In order for this mapping to work you need to set up one of |
| 293 | * the local to PCI aperatures to 16Mbytes in length translating to |
| 294 | * PCI configuration space starting at 0x0000.0000. |
| 295 | * |
| 296 | * PCI configuration cycles look like this: |
| 297 | * |
| 298 | * Type 0: |
| 299 | * |
Rob Herring | 29d3960 | 2012-07-13 16:27:43 -0500 | [diff] [blame] | 300 | * 3 3|3 3 2 2|2 2 2 2|2 2 2 2|1 1 1 1|1 1 1 1|1 1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | * 3 2|1 0 9 8|7 6 5 4|3 2 1 0|9 8 7 6|5 4 3 2|1 0 9 8|7 6 5 4|3 2 1 0 |
| 302 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 303 | * | | |D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|F|F|F|R|R|R|R|R|R|0|0| |
| 304 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 305 | * |
| 306 | * 31:11 Device select bit. |
| 307 | * 10:8 Function number |
| 308 | * 7:2 Register number |
| 309 | * |
| 310 | * Type 1: |
| 311 | * |
Rob Herring | 29d3960 | 2012-07-13 16:27:43 -0500 | [diff] [blame] | 312 | * 3 3|3 3 2 2|2 2 2 2|2 2 2 2|1 1 1 1|1 1 1 1|1 1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | * 3 2|1 0 9 8|7 6 5 4|3 2 1 0|9 8 7 6|5 4 3 2|1 0 9 8|7 6 5 4|3 2 1 0 |
| 314 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 315 | * | | | | | | | | | | |B|B|B|B|B|B|B|B|D|D|D|D|D|F|F|F|R|R|R|R|R|R|0|1| |
| 316 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 317 | * |
| 318 | * 31:24 reserved |
| 319 | * 23:16 bus number (8 bits = 128 possible buses) |
| 320 | * 15:11 Device number (5 bits) |
| 321 | * 10:8 function number |
| 322 | * 7:2 register number |
Rob Herring | 29d3960 | 2012-07-13 16:27:43 -0500 | [diff] [blame] | 323 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | */ |
Thomas Gleixner | bd31b85 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 325 | static DEFINE_RAW_SPINLOCK(v3_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | |
| 327 | #define PCI_BUS_NONMEM_START 0x00000000 |
| 328 | #define PCI_BUS_NONMEM_SIZE SZ_256M |
| 329 | |
| 330 | #define PCI_BUS_PREMEM_START PCI_BUS_NONMEM_START + PCI_BUS_NONMEM_SIZE |
| 331 | #define PCI_BUS_PREMEM_SIZE SZ_256M |
| 332 | |
| 333 | #if PCI_BUS_NONMEM_START & 0x000fffff |
| 334 | #error PCI_BUS_NONMEM_START must be megabyte aligned |
| 335 | #endif |
| 336 | #if PCI_BUS_PREMEM_START & 0x000fffff |
| 337 | #error PCI_BUS_PREMEM_START must be megabyte aligned |
| 338 | #endif |
| 339 | |
| 340 | #undef V3_LB_BASE_PREFETCH |
| 341 | #define V3_LB_BASE_PREFETCH 0 |
| 342 | |
Arnd Bergmann | b7a3f8d | 2012-09-14 20:16:39 +0000 | [diff] [blame] | 343 | static void __iomem *v3_open_config_window(struct pci_bus *bus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | unsigned int devfn, int offset) |
| 345 | { |
| 346 | unsigned int address, mapaddress, busnr; |
| 347 | |
| 348 | busnr = bus->number; |
| 349 | |
| 350 | /* |
| 351 | * Trap out illegal values |
| 352 | */ |
Sasha Levin | f7a9b36 | 2012-11-08 15:23:08 -0500 | [diff] [blame] | 353 | BUG_ON(offset > 255); |
| 354 | BUG_ON(busnr > 255); |
| 355 | BUG_ON(devfn > 255); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | |
| 357 | if (busnr == 0) { |
| 358 | int slot = PCI_SLOT(devfn); |
| 359 | |
| 360 | /* |
| 361 | * local bus segment so need a type 0 config cycle |
| 362 | * |
| 363 | * build the PCI configuration "address" with one-hot in |
| 364 | * A31-A11 |
| 365 | * |
| 366 | * mapaddress: |
| 367 | * 3:1 = config cycle (101) |
| 368 | * 0 = PCI A1 & A0 are 0 (0) |
| 369 | */ |
| 370 | address = PCI_FUNC(devfn) << 8; |
| 371 | mapaddress = V3_LB_MAP_TYPE_CONFIG; |
| 372 | |
| 373 | if (slot > 12) |
| 374 | /* |
| 375 | * high order bits are handled by the MAP register |
| 376 | */ |
| 377 | mapaddress |= 1 << (slot - 5); |
| 378 | else |
| 379 | /* |
| 380 | * low order bits handled directly in the address |
| 381 | */ |
| 382 | address |= 1 << (slot + 11); |
| 383 | } else { |
| 384 | /* |
| 385 | * not the local bus segment so need a type 1 config cycle |
| 386 | * |
| 387 | * address: |
| 388 | * 23:16 = bus number |
| 389 | * 15:11 = slot number (7:3 of devfn) |
| 390 | * 10:8 = func number (2:0 of devfn) |
| 391 | * |
| 392 | * mapaddress: |
| 393 | * 3:1 = config cycle (101) |
| 394 | * 0 = PCI A1 & A0 from host bus (1) |
| 395 | */ |
| 396 | mapaddress = V3_LB_MAP_TYPE_CONFIG | V3_LB_MAP_AD_LOW_EN; |
| 397 | address = (busnr << 16) | (devfn << 8); |
| 398 | } |
| 399 | |
| 400 | /* |
| 401 | * Set up base0 to see all 512Mbytes of memory space (not |
| 402 | * prefetchable), this frees up base1 for re-use by |
| 403 | * configuration memory |
| 404 | */ |
| 405 | v3_writel(V3_LB_BASE0, v3_addr_to_lb_base(PHYS_PCI_MEM_BASE) | |
| 406 | V3_LB_BASE_ADR_SIZE_512MB | V3_LB_BASE_ENABLE); |
| 407 | |
| 408 | /* |
| 409 | * Set up base1/map1 to point into configuration space. |
| 410 | */ |
| 411 | v3_writel(V3_LB_BASE1, v3_addr_to_lb_base(PHYS_PCI_CONFIG_BASE) | |
| 412 | V3_LB_BASE_ADR_SIZE_16MB | V3_LB_BASE_ENABLE); |
| 413 | v3_writew(V3_LB_MAP1, mapaddress); |
| 414 | |
| 415 | return PCI_CONFIG_VADDR + address + offset; |
| 416 | } |
| 417 | |
| 418 | static void v3_close_config_window(void) |
| 419 | { |
| 420 | /* |
| 421 | * Reassign base1 for use by prefetchable PCI memory |
| 422 | */ |
| 423 | v3_writel(V3_LB_BASE1, v3_addr_to_lb_base(PHYS_PCI_MEM_BASE + SZ_256M) | |
| 424 | V3_LB_BASE_ADR_SIZE_256MB | V3_LB_BASE_PREFETCH | |
| 425 | V3_LB_BASE_ENABLE); |
| 426 | v3_writew(V3_LB_MAP1, v3_addr_to_lb_map(PCI_BUS_PREMEM_START) | |
| 427 | V3_LB_MAP_TYPE_MEM_MULTIPLE); |
| 428 | |
| 429 | /* |
| 430 | * And shrink base0 back to a 256M window (NOTE: MAP0 already correct) |
| 431 | */ |
| 432 | v3_writel(V3_LB_BASE0, v3_addr_to_lb_base(PHYS_PCI_MEM_BASE) | |
| 433 | V3_LB_BASE_ADR_SIZE_256MB | V3_LB_BASE_ENABLE); |
| 434 | } |
| 435 | |
| 436 | static int v3_read_config(struct pci_bus *bus, unsigned int devfn, int where, |
| 437 | int size, u32 *val) |
| 438 | { |
Arnd Bergmann | b7a3f8d | 2012-09-14 20:16:39 +0000 | [diff] [blame] | 439 | void __iomem *addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | unsigned long flags; |
| 441 | u32 v; |
| 442 | |
Thomas Gleixner | bd31b85 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 443 | raw_spin_lock_irqsave(&v3_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | addr = v3_open_config_window(bus, devfn, where); |
| 445 | |
| 446 | switch (size) { |
| 447 | case 1: |
| 448 | v = __raw_readb(addr); |
| 449 | break; |
| 450 | |
| 451 | case 2: |
| 452 | v = __raw_readw(addr); |
| 453 | break; |
| 454 | |
| 455 | default: |
| 456 | v = __raw_readl(addr); |
| 457 | break; |
| 458 | } |
| 459 | |
| 460 | v3_close_config_window(); |
Thomas Gleixner | bd31b85 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 461 | raw_spin_unlock_irqrestore(&v3_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | |
| 463 | *val = v; |
| 464 | return PCIBIOS_SUCCESSFUL; |
| 465 | } |
| 466 | |
| 467 | static int v3_write_config(struct pci_bus *bus, unsigned int devfn, int where, |
| 468 | int size, u32 val) |
| 469 | { |
Arnd Bergmann | b7a3f8d | 2012-09-14 20:16:39 +0000 | [diff] [blame] | 470 | void __iomem *addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | unsigned long flags; |
| 472 | |
Thomas Gleixner | bd31b85 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 473 | raw_spin_lock_irqsave(&v3_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | addr = v3_open_config_window(bus, devfn, where); |
| 475 | |
| 476 | switch (size) { |
| 477 | case 1: |
| 478 | __raw_writeb((u8)val, addr); |
| 479 | __raw_readb(addr); |
| 480 | break; |
| 481 | |
| 482 | case 2: |
| 483 | __raw_writew((u16)val, addr); |
| 484 | __raw_readw(addr); |
| 485 | break; |
| 486 | |
| 487 | case 4: |
| 488 | __raw_writel(val, addr); |
| 489 | __raw_readl(addr); |
| 490 | break; |
| 491 | } |
| 492 | |
| 493 | v3_close_config_window(); |
Thomas Gleixner | bd31b85 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 494 | raw_spin_unlock_irqrestore(&v3_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | |
| 496 | return PCIBIOS_SUCCESSFUL; |
| 497 | } |
| 498 | |
Linus Walleij | f4bc4f0 | 2013-01-29 17:14:18 +0100 | [diff] [blame] | 499 | static struct pci_ops pci_v3_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | .read = v3_read_config, |
| 501 | .write = v3_write_config, |
| 502 | }; |
| 503 | |
| 504 | static struct resource non_mem = { |
| 505 | .name = "PCI non-prefetchable", |
| 506 | .start = PHYS_PCI_MEM_BASE + PCI_BUS_NONMEM_START, |
| 507 | .end = PHYS_PCI_MEM_BASE + PCI_BUS_NONMEM_START + PCI_BUS_NONMEM_SIZE - 1, |
| 508 | .flags = IORESOURCE_MEM, |
| 509 | }; |
| 510 | |
| 511 | static struct resource pre_mem = { |
| 512 | .name = "PCI prefetchable", |
| 513 | .start = PHYS_PCI_MEM_BASE + PCI_BUS_PREMEM_START, |
| 514 | .end = PHYS_PCI_MEM_BASE + PCI_BUS_PREMEM_START + PCI_BUS_PREMEM_SIZE - 1, |
| 515 | .flags = IORESOURCE_MEM | IORESOURCE_PREFETCH, |
| 516 | }; |
| 517 | |
Bjorn Helgaas | 37d1590 | 2011-10-28 16:26:16 -0600 | [diff] [blame] | 518 | static int __init pci_v3_setup_resources(struct pci_sys_data *sys) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | { |
| 520 | if (request_resource(&iomem_resource, &non_mem)) { |
| 521 | printk(KERN_ERR "PCI: unable to allocate non-prefetchable " |
| 522 | "memory region\n"); |
| 523 | return -EBUSY; |
| 524 | } |
| 525 | if (request_resource(&iomem_resource, &pre_mem)) { |
| 526 | release_resource(&non_mem); |
| 527 | printk(KERN_ERR "PCI: unable to allocate prefetchable " |
| 528 | "memory region\n"); |
| 529 | return -EBUSY; |
| 530 | } |
| 531 | |
| 532 | /* |
Bjorn Helgaas | 37d1590 | 2011-10-28 16:26:16 -0600 | [diff] [blame] | 533 | * the mem resource for this bus |
| 534 | * the prefetch mem resource for this bus |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | */ |
Bjorn Helgaas | 9f786d03 | 2012-02-23 20:19:01 -0700 | [diff] [blame] | 536 | pci_add_resource_offset(&sys->resources, &non_mem, sys->mem_offset); |
| 537 | pci_add_resource_offset(&sys->resources, &pre_mem, sys->mem_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | |
| 539 | return 1; |
| 540 | } |
| 541 | |
| 542 | /* |
| 543 | * These don't seem to be implemented on the Integrator I have, which |
| 544 | * means I can't get additional information on the reason for the pm2fb |
| 545 | * problems. I suppose I'll just have to mind-meld with the machine. ;) |
| 546 | */ |
Linus Walleij | 379df27 | 2012-11-17 19:24:23 +0100 | [diff] [blame] | 547 | static void __iomem *ap_syscon_base; |
| 548 | #define INTEGRATOR_SC_PCIENABLE_OFFSET 0x18 |
| 549 | #define INTEGRATOR_SC_LBFADDR_OFFSET 0x20 |
| 550 | #define INTEGRATOR_SC_LBFCODE_OFFSET 0x24 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | |
| 552 | static int |
| 553 | v3_pci_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs) |
| 554 | { |
| 555 | unsigned long pc = instruction_pointer(regs); |
| 556 | unsigned long instr = *(unsigned long *)pc; |
| 557 | #if 0 |
| 558 | char buf[128]; |
| 559 | |
| 560 | sprintf(buf, "V3 fault: addr 0x%08lx, FSR 0x%03x, PC 0x%08lx [%08lx] LBFADDR=%08x LBFCODE=%02x ISTAT=%02x\n", |
Linus Walleij | 379df27 | 2012-11-17 19:24:23 +0100 | [diff] [blame] | 561 | addr, fsr, pc, instr, __raw_readl(ap_syscon_base + INTEGRATOR_SC_LBFADDR_OFFSET), __raw_readl(ap_syscon_base + INTEGRATOR_SC_LBFCODE_OFFSET) & 255, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | v3_readb(V3_LB_ISTAT)); |
| 563 | printk(KERN_DEBUG "%s", buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | #endif |
| 565 | |
| 566 | v3_writeb(V3_LB_ISTAT, 0); |
Linus Walleij | 379df27 | 2012-11-17 19:24:23 +0100 | [diff] [blame] | 567 | __raw_writel(3, ap_syscon_base + INTEGRATOR_SC_PCIENABLE_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | |
| 569 | /* |
| 570 | * If the instruction being executed was a read, |
| 571 | * make it look like it read all-ones. |
| 572 | */ |
| 573 | if ((instr & 0x0c100000) == 0x04100000) { |
| 574 | int reg = (instr >> 12) & 15; |
| 575 | unsigned long val; |
| 576 | |
| 577 | if (instr & 0x00400000) |
| 578 | val = 255; |
| 579 | else |
| 580 | val = -1; |
| 581 | |
| 582 | regs->uregs[reg] = val; |
| 583 | regs->ARM_pc += 4; |
| 584 | return 0; |
| 585 | } |
| 586 | |
| 587 | if ((instr & 0x0e100090) == 0x00100090) { |
| 588 | int reg = (instr >> 12) & 15; |
| 589 | |
| 590 | regs->uregs[reg] = -1; |
| 591 | regs->ARM_pc += 4; |
| 592 | return 0; |
| 593 | } |
| 594 | |
| 595 | return 1; |
| 596 | } |
| 597 | |
Jeff Garzik | e8f2af1 | 2007-10-26 05:40:25 -0400 | [diff] [blame] | 598 | static irqreturn_t v3_irq(int dummy, void *devid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | { |
| 600 | #ifdef CONFIG_DEBUG_LL |
Linus Torvalds | 0cd61b6 | 2006-10-06 10:53:39 -0700 | [diff] [blame] | 601 | struct pt_regs *regs = get_irq_regs(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | unsigned long pc = instruction_pointer(regs); |
| 603 | unsigned long instr = *(unsigned long *)pc; |
| 604 | char buf[128]; |
Russell King | 7c28472 | 2008-05-23 19:35:52 +0100 | [diff] [blame] | 605 | extern void printascii(const char *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | |
Jeff Garzik | e8f2af1 | 2007-10-26 05:40:25 -0400 | [diff] [blame] | 607 | sprintf(buf, "V3 int %d: pc=0x%08lx [%08lx] LBFADDR=%08x LBFCODE=%02x " |
| 608 | "ISTAT=%02x\n", IRQ_AP_V3INT, pc, instr, |
Linus Walleij | 379df27 | 2012-11-17 19:24:23 +0100 | [diff] [blame] | 609 | __raw_readl(ap_syscon_base + INTEGRATOR_SC_LBFADDR_OFFSET), |
| 610 | __raw_readl(ap_syscon_base + INTEGRATOR_SC_LBFCODE_OFFSET) & 255, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | v3_readb(V3_LB_ISTAT)); |
| 612 | printascii(buf); |
| 613 | #endif |
| 614 | |
| 615 | v3_writew(V3_PCI_STAT, 0xf000); |
| 616 | v3_writeb(V3_LB_ISTAT, 0); |
Linus Walleij | 379df27 | 2012-11-17 19:24:23 +0100 | [diff] [blame] | 617 | __raw_writel(3, ap_syscon_base + INTEGRATOR_SC_PCIENABLE_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | |
| 619 | #ifdef CONFIG_DEBUG_LL |
| 620 | /* |
| 621 | * If the instruction being executed was a read, |
| 622 | * make it look like it read all-ones. |
| 623 | */ |
| 624 | if ((instr & 0x0c100000) == 0x04100000) { |
| 625 | int reg = (instr >> 16) & 15; |
| 626 | sprintf(buf, " reg%d = %08lx\n", reg, regs->uregs[reg]); |
| 627 | printascii(buf); |
| 628 | } |
| 629 | #endif |
| 630 | return IRQ_HANDLED; |
| 631 | } |
| 632 | |
Linus Walleij | f4bc4f0 | 2013-01-29 17:14:18 +0100 | [diff] [blame] | 633 | static int __init pci_v3_setup(int nr, struct pci_sys_data *sys) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | { |
| 635 | int ret = 0; |
| 636 | |
Linus Walleij | 67c6b2e | 2013-01-10 10:18:49 +0100 | [diff] [blame] | 637 | if (!ap_syscon_base) |
| 638 | return -EINVAL; |
| 639 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | if (nr == 0) { |
| 641 | sys->mem_offset = PHYS_PCI_MEM_BASE; |
Bjorn Helgaas | 37d1590 | 2011-10-28 16:26:16 -0600 | [diff] [blame] | 642 | ret = pci_v3_setup_resources(sys); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | return ret; |
| 646 | } |
| 647 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | /* |
| 649 | * V3_LB_BASE? - local bus address |
| 650 | * V3_LB_MAP? - pci bus address |
| 651 | */ |
Linus Walleij | f4bc4f0 | 2013-01-29 17:14:18 +0100 | [diff] [blame] | 652 | static void __init pci_v3_preinit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | { |
| 654 | unsigned long flags; |
| 655 | unsigned int temp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | |
Rob Herring | c9d95fb | 2011-06-28 21:16:13 -0500 | [diff] [blame] | 657 | pcibios_min_mem = 0x00100000; |
| 658 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | /* |
| 660 | * Hook in our fault handler for PCI errors |
| 661 | */ |
Kirill A. Shutemov | 6338a6a | 2010-07-22 13:18:19 +0100 | [diff] [blame] | 662 | hook_fault_code(4, v3_pci_fault, SIGBUS, 0, "external abort on linefetch"); |
| 663 | hook_fault_code(6, v3_pci_fault, SIGBUS, 0, "external abort on linefetch"); |
| 664 | hook_fault_code(8, v3_pci_fault, SIGBUS, 0, "external abort on non-linefetch"); |
| 665 | hook_fault_code(10, v3_pci_fault, SIGBUS, 0, "external abort on non-linefetch"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | |
Thomas Gleixner | bd31b85 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 667 | raw_spin_lock_irqsave(&v3_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | |
| 669 | /* |
| 670 | * Unlock V3 registers, but only if they were previously locked. |
| 671 | */ |
| 672 | if (v3_readw(V3_SYSTEM) & V3_SYSTEM_M_LOCK) |
| 673 | v3_writew(V3_SYSTEM, 0xa05f); |
| 674 | |
| 675 | /* |
| 676 | * Setup window 0 - PCI non-prefetchable memory |
| 677 | * Local: 0x40000000 Bus: 0x00000000 Size: 256MB |
| 678 | */ |
| 679 | v3_writel(V3_LB_BASE0, v3_addr_to_lb_base(PHYS_PCI_MEM_BASE) | |
| 680 | V3_LB_BASE_ADR_SIZE_256MB | V3_LB_BASE_ENABLE); |
| 681 | v3_writew(V3_LB_MAP0, v3_addr_to_lb_map(PCI_BUS_NONMEM_START) | |
| 682 | V3_LB_MAP_TYPE_MEM); |
| 683 | |
| 684 | /* |
| 685 | * Setup window 1 - PCI prefetchable memory |
| 686 | * Local: 0x50000000 Bus: 0x10000000 Size: 256MB |
| 687 | */ |
| 688 | v3_writel(V3_LB_BASE1, v3_addr_to_lb_base(PHYS_PCI_MEM_BASE + SZ_256M) | |
| 689 | V3_LB_BASE_ADR_SIZE_256MB | V3_LB_BASE_PREFETCH | |
| 690 | V3_LB_BASE_ENABLE); |
| 691 | v3_writew(V3_LB_MAP1, v3_addr_to_lb_map(PCI_BUS_PREMEM_START) | |
| 692 | V3_LB_MAP_TYPE_MEM_MULTIPLE); |
| 693 | |
| 694 | /* |
| 695 | * Setup window 2 - PCI IO |
| 696 | */ |
| 697 | v3_writel(V3_LB_BASE2, v3_addr_to_lb_base2(PHYS_PCI_IO_BASE) | |
| 698 | V3_LB_BASE_ENABLE); |
| 699 | v3_writew(V3_LB_MAP2, v3_addr_to_lb_map2(0)); |
| 700 | |
| 701 | /* |
| 702 | * Disable PCI to host IO cycles |
| 703 | */ |
| 704 | temp = v3_readw(V3_PCI_CFG) & ~V3_PCI_CFG_M_I2O_EN; |
| 705 | temp |= V3_PCI_CFG_M_IO_REG_DIS | V3_PCI_CFG_M_IO_DIS; |
| 706 | v3_writew(V3_PCI_CFG, temp); |
| 707 | |
| 708 | printk(KERN_DEBUG "FIFO_CFG: %04x FIFO_PRIO: %04x\n", |
| 709 | v3_readw(V3_FIFO_CFG), v3_readw(V3_FIFO_PRIORITY)); |
| 710 | |
| 711 | /* |
| 712 | * Set the V3 FIFO such that writes have higher priority than |
| 713 | * reads, and local bus write causes local bus read fifo flush. |
| 714 | * Same for PCI. |
| 715 | */ |
| 716 | v3_writew(V3_FIFO_PRIORITY, 0x0a0a); |
| 717 | |
| 718 | /* |
| 719 | * Re-lock the system register. |
| 720 | */ |
| 721 | temp = v3_readw(V3_SYSTEM) | V3_SYSTEM_M_LOCK; |
| 722 | v3_writew(V3_SYSTEM, temp); |
| 723 | |
| 724 | /* |
| 725 | * Clear any error conditions, and enable write errors. |
| 726 | */ |
| 727 | v3_writeb(V3_LB_ISTAT, 0); |
| 728 | v3_writew(V3_LB_CFG, v3_readw(V3_LB_CFG) | (1 << 10)); |
| 729 | v3_writeb(V3_LB_IMASK, 0x28); |
Linus Walleij | 379df27 | 2012-11-17 19:24:23 +0100 | [diff] [blame] | 730 | __raw_writel(3, ap_syscon_base + INTEGRATOR_SC_PCIENABLE_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | |
Thomas Gleixner | bd31b85 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 732 | raw_spin_unlock_irqrestore(&v3_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | } |
| 734 | |
Linus Walleij | f4bc4f0 | 2013-01-29 17:14:18 +0100 | [diff] [blame] | 735 | static void __init pci_v3_postinit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | { |
| 737 | unsigned int pci_cmd; |
| 738 | |
| 739 | pci_cmd = PCI_COMMAND_MEMORY | |
| 740 | PCI_COMMAND_MASTER | PCI_COMMAND_INVALIDATE; |
| 741 | |
| 742 | v3_writew(V3_PCI_CMD, pci_cmd); |
| 743 | |
| 744 | v3_writeb(V3_LB_ISTAT, ~0x40); |
| 745 | v3_writeb(V3_LB_IMASK, 0x68); |
| 746 | |
| 747 | #if 0 |
| 748 | ret = request_irq(IRQ_AP_LBUSTIMEOUT, lb_timeout, 0, "bus timeout", NULL); |
| 749 | if (ret) |
| 750 | printk(KERN_ERR "PCI: unable to grab local bus timeout " |
| 751 | "interrupt: %d\n", ret); |
| 752 | #endif |
Russell King | 863dab4 | 2006-08-28 12:47:05 +0100 | [diff] [blame] | 753 | |
| 754 | register_isa_ports(PHYS_PCI_MEM_BASE, PHYS_PCI_IO_BASE, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | } |
Linus Walleij | f4bc4f0 | 2013-01-29 17:14:18 +0100 | [diff] [blame] | 756 | |
| 757 | /* |
| 758 | * A small note about bridges and interrupts. The DECchip 21050 (and |
| 759 | * later) adheres to the PCI-PCI bridge specification. This says that |
| 760 | * the interrupts on the other side of a bridge are swizzled in the |
| 761 | * following manner: |
| 762 | * |
| 763 | * Dev Interrupt Interrupt |
| 764 | * Pin on Pin on |
| 765 | * Device Connector |
| 766 | * |
| 767 | * 4 A A |
| 768 | * B B |
| 769 | * C C |
| 770 | * D D |
| 771 | * |
| 772 | * 5 A B |
| 773 | * B C |
| 774 | * C D |
| 775 | * D A |
| 776 | * |
| 777 | * 6 A C |
| 778 | * B D |
| 779 | * C A |
| 780 | * D B |
| 781 | * |
| 782 | * 7 A D |
| 783 | * B A |
| 784 | * C B |
| 785 | * D C |
| 786 | * |
| 787 | * Where A = pin 1, B = pin 2 and so on and pin=0 = default = A. |
| 788 | * Thus, each swizzle is ((pin-1) + (device#-4)) % 4 |
| 789 | */ |
| 790 | |
| 791 | /* |
| 792 | * This routine handles multiple bridges. |
| 793 | */ |
Linus Walleij | 86adc39 | 2013-02-02 23:16:57 +0100 | [diff] [blame] | 794 | static u8 __init pci_v3_swizzle(struct pci_dev *dev, u8 *pinp) |
Linus Walleij | f4bc4f0 | 2013-01-29 17:14:18 +0100 | [diff] [blame] | 795 | { |
| 796 | if (*pinp == 0) |
| 797 | *pinp = 1; |
| 798 | |
| 799 | return pci_common_swizzle(dev, pinp); |
| 800 | } |
| 801 | |
| 802 | static int irq_tab[4] __initdata = { |
| 803 | IRQ_AP_PCIINT0, IRQ_AP_PCIINT1, IRQ_AP_PCIINT2, IRQ_AP_PCIINT3 |
| 804 | }; |
| 805 | |
| 806 | /* |
| 807 | * map the specified device/slot/pin to an IRQ. This works out such |
| 808 | * that slot 9 pin 1 is INT0, pin 2 is INT1, and slot 10 pin 1 is INT1. |
| 809 | */ |
Linus Walleij | 86adc39 | 2013-02-02 23:16:57 +0100 | [diff] [blame] | 810 | static int __init pci_v3_map_irq(const struct pci_dev *dev, u8 slot, u8 pin) |
Linus Walleij | f4bc4f0 | 2013-01-29 17:14:18 +0100 | [diff] [blame] | 811 | { |
| 812 | int intnr = ((slot - 9) + (pin - 1)) & 3; |
| 813 | |
| 814 | return irq_tab[intnr]; |
| 815 | } |
| 816 | |
Linus Walleij | 86adc39 | 2013-02-02 23:16:57 +0100 | [diff] [blame] | 817 | static struct hw_pci pci_v3 __initdata = { |
| 818 | .swizzle = pci_v3_swizzle, |
| 819 | .map_irq = pci_v3_map_irq, |
Linus Walleij | f4bc4f0 | 2013-01-29 17:14:18 +0100 | [diff] [blame] | 820 | .setup = pci_v3_setup, |
| 821 | .nr_controllers = 1, |
| 822 | .ops = &pci_v3_ops, |
| 823 | .preinit = pci_v3_preinit, |
| 824 | .postinit = pci_v3_postinit, |
| 825 | }; |
| 826 | |
Linus Walleij | 86adc39 | 2013-02-02 23:16:57 +0100 | [diff] [blame] | 827 | static int __init pci_v3_probe(struct platform_device *pdev) |
Linus Walleij | f4bc4f0 | 2013-01-29 17:14:18 +0100 | [diff] [blame] | 828 | { |
Linus Walleij | 5283456 | 2013-04-04 14:02:57 +0200 | [diff] [blame] | 829 | int ret; |
| 830 | |
Linus Walleij | 03884f4 | 2013-02-03 00:06:04 +0100 | [diff] [blame] | 831 | /* Remap the Integrator system controller */ |
| 832 | ap_syscon_base = ioremap(INTEGRATOR_SC_BASE, 0x100); |
| 833 | if (!ap_syscon_base) { |
| 834 | dev_err(&pdev->dev, "unable to remap the AP syscon for PCIv3\n"); |
| 835 | return -ENODEV; |
| 836 | } |
| 837 | |
Linus Walleij | 5283456 | 2013-04-04 14:02:57 +0200 | [diff] [blame] | 838 | ret = devm_request_irq(&pdev->dev, IRQ_AP_V3INT, v3_irq, 0, "V3", NULL); |
| 839 | if (ret) { |
| 840 | dev_err(&pdev->dev, "unable to grab PCI error interrupt: %d\n", |
| 841 | ret); |
| 842 | return -ENODEV; |
| 843 | } |
| 844 | |
Linus Walleij | 86adc39 | 2013-02-02 23:16:57 +0100 | [diff] [blame] | 845 | pci_common_init(&pci_v3); |
Linus Walleij | 5283456 | 2013-04-04 14:02:57 +0200 | [diff] [blame] | 846 | |
Linus Walleij | f4bc4f0 | 2013-01-29 17:14:18 +0100 | [diff] [blame] | 847 | return 0; |
| 848 | } |
| 849 | |
Linus Walleij | 86adc39 | 2013-02-02 23:16:57 +0100 | [diff] [blame] | 850 | static struct platform_driver pci_v3_driver = { |
| 851 | .driver = { |
| 852 | .name = "pci-v3", |
| 853 | }, |
| 854 | }; |
| 855 | |
| 856 | static int __init pci_v3_init(void) |
| 857 | { |
| 858 | return platform_driver_probe(&pci_v3_driver, pci_v3_probe); |
| 859 | } |
| 860 | |
| 861 | subsys_initcall(pci_v3_init); |