blob: 000edcda4596fb490695bd6d1766be3dd7d355a7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/kernel.h>
24#include <linux/pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <linux/ioport.h>
26#include <linux/interrupt.h>
27#include <linux/spinlock.h>
28#include <linux/init.h>
Russell Kingfced80c2008-09-06 12:10:45 +010029#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Russell Kinga09e64f2008-08-05 16:14:15 +010031#include <mach/hardware.h>
Russell Kinga285edc2010-01-14 19:59:37 +000032#include <mach/platform.h>
Linus Walleij695436e2012-02-26 10:46:48 +010033#include <mach/irqs.h>
34
Alexey Dobriyand43c36d2009-10-07 17:09:06 +040035#include <asm/signal.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <asm/mach/pci.h>
Russell Kingc6af66b2007-05-17 10:16:55 +010037#include <asm/irq_regs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
39#include <asm/hardware/pci_v3.h>
40
41/*
42 * The V3 PCI interface chip in Integrator provides several windows from
43 * local bus memory into the PCI memory areas. Unfortunately, there
Rob Herring29d39602012-07-13 16:27:43 -050044 * are not really enough windows for our usage, therefore we reuse
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 * one of the windows for access to PCI configuration space. The
46 * memory map is as follows:
Rob Herring29d39602012-07-13 16:27:43 -050047 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 * Local Bus Memory Usage
Rob Herring29d39602012-07-13 16:27:43 -050049 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 * 40000000 - 4FFFFFFF PCI memory. 256M non-prefetchable
51 * 50000000 - 5FFFFFFF PCI memory. 256M prefetchable
52 * 60000000 - 60FFFFFF PCI IO. 16M
53 * 61000000 - 61FFFFFF PCI Configuration. 16M
Rob Herring29d39602012-07-13 16:27:43 -050054 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 * There are three V3 windows, each described by a pair of V3 registers.
56 * These are LB_BASE0/LB_MAP0, LB_BASE1/LB_MAP1 and LB_BASE2/LB_MAP2.
57 * Base0 and Base1 can be used for any type of PCI memory access. Base2
58 * can be used either for PCI I/O or for I20 accesses. By default, uHAL
59 * uses this only for PCI IO space.
Rob Herring29d39602012-07-13 16:27:43 -050060 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 * Normally these spaces are mapped using the following base registers:
Rob Herring29d39602012-07-13 16:27:43 -050062 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 * Usage Local Bus Memory Base/Map registers used
Rob Herring29d39602012-07-13 16:27:43 -050064 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 * Mem 40000000 - 4FFFFFFF LB_BASE0/LB_MAP0
66 * Mem 50000000 - 5FFFFFFF LB_BASE1/LB_MAP1
67 * IO 60000000 - 60FFFFFF LB_BASE2/LB_MAP2
68 * Cfg 61000000 - 61FFFFFF
Rob Herring29d39602012-07-13 16:27:43 -050069 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 * This means that I20 and PCI configuration space accesses will fail.
Rob Herring29d39602012-07-13 16:27:43 -050071 * When PCI configuration accesses are needed (via the uHAL PCI
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 * configuration space primitives) we must remap the spaces as follows:
Rob Herring29d39602012-07-13 16:27:43 -050073 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 * Usage Local Bus Memory Base/Map registers used
Rob Herring29d39602012-07-13 16:27:43 -050075 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 * Mem 40000000 - 4FFFFFFF LB_BASE0/LB_MAP0
77 * Mem 50000000 - 5FFFFFFF LB_BASE0/LB_MAP0
78 * IO 60000000 - 60FFFFFF LB_BASE2/LB_MAP2
79 * Cfg 61000000 - 61FFFFFF LB_BASE1/LB_MAP1
Rob Herring29d39602012-07-13 16:27:43 -050080 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 * To make this work, the code depends on overlapping windows working.
Rob Herring29d39602012-07-13 16:27:43 -050082 * The V3 chip translates an address by checking its range within
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 * each of the BASE/MAP pairs in turn (in ascending register number
84 * order). It will use the first matching pair. So, for example,
85 * if the same address is mapped by both LB_BASE0/LB_MAP0 and
Rob Herring29d39602012-07-13 16:27:43 -050086 * LB_BASE1/LB_MAP1, the V3 will use the translation from
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 * LB_BASE0/LB_MAP0.
Rob Herring29d39602012-07-13 16:27:43 -050088 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 * To allow PCI Configuration space access, the code enlarges the
90 * window mapped by LB_BASE0/LB_MAP0 from 256M to 512M. This occludes
91 * the windows currently mapped by LB_BASE1/LB_MAP1 so that it can
92 * be remapped for use by configuration cycles.
Rob Herring29d39602012-07-13 16:27:43 -050093 *
94 * At the end of the PCI Configuration space accesses,
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 * LB_BASE1/LB_MAP1 is reset to map PCI Memory. Finally the window
96 * mapped by LB_BASE0/LB_MAP0 is reduced in size from 512M to 256M to
97 * reveal the now restored LB_BASE1/LB_MAP1 window.
Rob Herring29d39602012-07-13 16:27:43 -050098 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 * NOTE: We do not set up I2O mapping. I suspect that this is only
100 * for an intelligent (target) device. Using I2O disables most of
101 * the mappings into PCI memory.
102 */
103
104// V3 access routines
105#define v3_writeb(o,v) __raw_writeb(v, PCI_V3_VADDR + (unsigned int)(o))
106#define v3_readb(o) (__raw_readb(PCI_V3_VADDR + (unsigned int)(o)))
107
108#define v3_writew(o,v) __raw_writew(v, PCI_V3_VADDR + (unsigned int)(o))
109#define v3_readw(o) (__raw_readw(PCI_V3_VADDR + (unsigned int)(o)))
110
111#define v3_writel(o,v) __raw_writel(v, PCI_V3_VADDR + (unsigned int)(o))
112#define v3_readl(o) (__raw_readl(PCI_V3_VADDR + (unsigned int)(o)))
113
114/*============================================================================
115 *
116 * routine: uHALir_PCIMakeConfigAddress()
117 *
118 * parameters: bus = which bus
119 * device = which device
120 * function = which function
121 * offset = configuration space register we are interested in
122 *
123 * description: this routine will generate a platform dependent config
124 * address.
125 *
126 * calls: none
127 *
128 * returns: configuration address to play on the PCI bus
129 *
Rob Herring29d39602012-07-13 16:27:43 -0500130 * To generate the appropriate PCI configuration cycles in the PCI
131 * configuration address space, you present the V3 with the following pattern
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 * (which is very nearly a type 1 (except that the lower two bits are 00 and
133 * not 01). In order for this mapping to work you need to set up one of
134 * the local to PCI aperatures to 16Mbytes in length translating to
135 * PCI configuration space starting at 0x0000.0000.
136 *
137 * PCI configuration cycles look like this:
138 *
139 * Type 0:
140 *
Rob Herring29d39602012-07-13 16:27:43 -0500141 * 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 Torvalds1da177e2005-04-16 15:20:36 -0700142 * 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
143 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
144 * | | |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|
145 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
146 *
147 * 31:11 Device select bit.
148 * 10:8 Function number
149 * 7:2 Register number
150 *
151 * Type 1:
152 *
Rob Herring29d39602012-07-13 16:27:43 -0500153 * 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 Torvalds1da177e2005-04-16 15:20:36 -0700154 * 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
155 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
156 * | | | | | | | | | | |B|B|B|B|B|B|B|B|D|D|D|D|D|F|F|F|R|R|R|R|R|R|0|1|
157 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
158 *
159 * 31:24 reserved
160 * 23:16 bus number (8 bits = 128 possible buses)
161 * 15:11 Device number (5 bits)
162 * 10:8 function number
163 * 7:2 register number
Rob Herring29d39602012-07-13 16:27:43 -0500164 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 */
Thomas Gleixnerbd31b852009-07-03 08:44:46 -0500166static DEFINE_RAW_SPINLOCK(v3_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
168#define PCI_BUS_NONMEM_START 0x00000000
169#define PCI_BUS_NONMEM_SIZE SZ_256M
170
171#define PCI_BUS_PREMEM_START PCI_BUS_NONMEM_START + PCI_BUS_NONMEM_SIZE
172#define PCI_BUS_PREMEM_SIZE SZ_256M
173
174#if PCI_BUS_NONMEM_START & 0x000fffff
175#error PCI_BUS_NONMEM_START must be megabyte aligned
176#endif
177#if PCI_BUS_PREMEM_START & 0x000fffff
178#error PCI_BUS_PREMEM_START must be megabyte aligned
179#endif
180
181#undef V3_LB_BASE_PREFETCH
182#define V3_LB_BASE_PREFETCH 0
183
Arnd Bergmannb7a3f8d2012-09-14 20:16:39 +0000184static void __iomem *v3_open_config_window(struct pci_bus *bus,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 unsigned int devfn, int offset)
186{
187 unsigned int address, mapaddress, busnr;
188
189 busnr = bus->number;
190
191 /*
192 * Trap out illegal values
193 */
194 if (offset > 255)
195 BUG();
196 if (busnr > 255)
197 BUG();
198 if (devfn > 255)
199 BUG();
200
201 if (busnr == 0) {
202 int slot = PCI_SLOT(devfn);
203
204 /*
205 * local bus segment so need a type 0 config cycle
206 *
207 * build the PCI configuration "address" with one-hot in
208 * A31-A11
209 *
210 * mapaddress:
211 * 3:1 = config cycle (101)
212 * 0 = PCI A1 & A0 are 0 (0)
213 */
214 address = PCI_FUNC(devfn) << 8;
215 mapaddress = V3_LB_MAP_TYPE_CONFIG;
216
217 if (slot > 12)
218 /*
219 * high order bits are handled by the MAP register
220 */
221 mapaddress |= 1 << (slot - 5);
222 else
223 /*
224 * low order bits handled directly in the address
225 */
226 address |= 1 << (slot + 11);
227 } else {
228 /*
229 * not the local bus segment so need a type 1 config cycle
230 *
231 * address:
232 * 23:16 = bus number
233 * 15:11 = slot number (7:3 of devfn)
234 * 10:8 = func number (2:0 of devfn)
235 *
236 * mapaddress:
237 * 3:1 = config cycle (101)
238 * 0 = PCI A1 & A0 from host bus (1)
239 */
240 mapaddress = V3_LB_MAP_TYPE_CONFIG | V3_LB_MAP_AD_LOW_EN;
241 address = (busnr << 16) | (devfn << 8);
242 }
243
244 /*
245 * Set up base0 to see all 512Mbytes of memory space (not
246 * prefetchable), this frees up base1 for re-use by
247 * configuration memory
248 */
249 v3_writel(V3_LB_BASE0, v3_addr_to_lb_base(PHYS_PCI_MEM_BASE) |
250 V3_LB_BASE_ADR_SIZE_512MB | V3_LB_BASE_ENABLE);
251
252 /*
253 * Set up base1/map1 to point into configuration space.
254 */
255 v3_writel(V3_LB_BASE1, v3_addr_to_lb_base(PHYS_PCI_CONFIG_BASE) |
256 V3_LB_BASE_ADR_SIZE_16MB | V3_LB_BASE_ENABLE);
257 v3_writew(V3_LB_MAP1, mapaddress);
258
259 return PCI_CONFIG_VADDR + address + offset;
260}
261
262static void v3_close_config_window(void)
263{
264 /*
265 * Reassign base1 for use by prefetchable PCI memory
266 */
267 v3_writel(V3_LB_BASE1, v3_addr_to_lb_base(PHYS_PCI_MEM_BASE + SZ_256M) |
268 V3_LB_BASE_ADR_SIZE_256MB | V3_LB_BASE_PREFETCH |
269 V3_LB_BASE_ENABLE);
270 v3_writew(V3_LB_MAP1, v3_addr_to_lb_map(PCI_BUS_PREMEM_START) |
271 V3_LB_MAP_TYPE_MEM_MULTIPLE);
272
273 /*
274 * And shrink base0 back to a 256M window (NOTE: MAP0 already correct)
275 */
276 v3_writel(V3_LB_BASE0, v3_addr_to_lb_base(PHYS_PCI_MEM_BASE) |
277 V3_LB_BASE_ADR_SIZE_256MB | V3_LB_BASE_ENABLE);
278}
279
280static int v3_read_config(struct pci_bus *bus, unsigned int devfn, int where,
281 int size, u32 *val)
282{
Arnd Bergmannb7a3f8d2012-09-14 20:16:39 +0000283 void __iomem *addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 unsigned long flags;
285 u32 v;
286
Thomas Gleixnerbd31b852009-07-03 08:44:46 -0500287 raw_spin_lock_irqsave(&v3_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 addr = v3_open_config_window(bus, devfn, where);
289
290 switch (size) {
291 case 1:
292 v = __raw_readb(addr);
293 break;
294
295 case 2:
296 v = __raw_readw(addr);
297 break;
298
299 default:
300 v = __raw_readl(addr);
301 break;
302 }
303
304 v3_close_config_window();
Thomas Gleixnerbd31b852009-07-03 08:44:46 -0500305 raw_spin_unlock_irqrestore(&v3_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
307 *val = v;
308 return PCIBIOS_SUCCESSFUL;
309}
310
311static int v3_write_config(struct pci_bus *bus, unsigned int devfn, int where,
312 int size, u32 val)
313{
Arnd Bergmannb7a3f8d2012-09-14 20:16:39 +0000314 void __iomem *addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 unsigned long flags;
316
Thomas Gleixnerbd31b852009-07-03 08:44:46 -0500317 raw_spin_lock_irqsave(&v3_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 addr = v3_open_config_window(bus, devfn, where);
319
320 switch (size) {
321 case 1:
322 __raw_writeb((u8)val, addr);
323 __raw_readb(addr);
324 break;
325
326 case 2:
327 __raw_writew((u16)val, addr);
328 __raw_readw(addr);
329 break;
330
331 case 4:
332 __raw_writel(val, addr);
333 __raw_readl(addr);
334 break;
335 }
336
337 v3_close_config_window();
Thomas Gleixnerbd31b852009-07-03 08:44:46 -0500338 raw_spin_unlock_irqrestore(&v3_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339
340 return PCIBIOS_SUCCESSFUL;
341}
342
Russell Kingc23bfc32012-03-10 12:49:16 +0000343struct pci_ops pci_v3_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 .read = v3_read_config,
345 .write = v3_write_config,
346};
347
348static struct resource non_mem = {
349 .name = "PCI non-prefetchable",
350 .start = PHYS_PCI_MEM_BASE + PCI_BUS_NONMEM_START,
351 .end = PHYS_PCI_MEM_BASE + PCI_BUS_NONMEM_START + PCI_BUS_NONMEM_SIZE - 1,
352 .flags = IORESOURCE_MEM,
353};
354
355static struct resource pre_mem = {
356 .name = "PCI prefetchable",
357 .start = PHYS_PCI_MEM_BASE + PCI_BUS_PREMEM_START,
358 .end = PHYS_PCI_MEM_BASE + PCI_BUS_PREMEM_START + PCI_BUS_PREMEM_SIZE - 1,
359 .flags = IORESOURCE_MEM | IORESOURCE_PREFETCH,
360};
361
Bjorn Helgaas37d15902011-10-28 16:26:16 -0600362static int __init pci_v3_setup_resources(struct pci_sys_data *sys)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363{
364 if (request_resource(&iomem_resource, &non_mem)) {
365 printk(KERN_ERR "PCI: unable to allocate non-prefetchable "
366 "memory region\n");
367 return -EBUSY;
368 }
369 if (request_resource(&iomem_resource, &pre_mem)) {
370 release_resource(&non_mem);
371 printk(KERN_ERR "PCI: unable to allocate prefetchable "
372 "memory region\n");
373 return -EBUSY;
374 }
375
376 /*
Bjorn Helgaas37d15902011-10-28 16:26:16 -0600377 * the mem resource for this bus
378 * the prefetch mem resource for this bus
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 */
Bjorn Helgaas9f786d02012-02-23 20:19:01 -0700380 pci_add_resource_offset(&sys->resources, &non_mem, sys->mem_offset);
381 pci_add_resource_offset(&sys->resources, &pre_mem, sys->mem_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
383 return 1;
384}
385
386/*
387 * These don't seem to be implemented on the Integrator I have, which
388 * means I can't get additional information on the reason for the pm2fb
389 * problems. I suppose I'll just have to mind-meld with the machine. ;)
390 */
Linus Walleij379df272012-11-17 19:24:23 +0100391static void __iomem *ap_syscon_base;
392#define INTEGRATOR_SC_PCIENABLE_OFFSET 0x18
393#define INTEGRATOR_SC_LBFADDR_OFFSET 0x20
394#define INTEGRATOR_SC_LBFCODE_OFFSET 0x24
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
396static int
397v3_pci_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
398{
399 unsigned long pc = instruction_pointer(regs);
400 unsigned long instr = *(unsigned long *)pc;
401#if 0
402 char buf[128];
403
404 sprintf(buf, "V3 fault: addr 0x%08lx, FSR 0x%03x, PC 0x%08lx [%08lx] LBFADDR=%08x LBFCODE=%02x ISTAT=%02x\n",
Linus Walleij379df272012-11-17 19:24:23 +0100405 addr, fsr, pc, instr, __raw_readl(ap_syscon_base + INTEGRATOR_SC_LBFADDR_OFFSET), __raw_readl(ap_syscon_base + INTEGRATOR_SC_LBFCODE_OFFSET) & 255,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 v3_readb(V3_LB_ISTAT));
407 printk(KERN_DEBUG "%s", buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408#endif
409
410 v3_writeb(V3_LB_ISTAT, 0);
Linus Walleij379df272012-11-17 19:24:23 +0100411 __raw_writel(3, ap_syscon_base + INTEGRATOR_SC_PCIENABLE_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
413 /*
414 * If the instruction being executed was a read,
415 * make it look like it read all-ones.
416 */
417 if ((instr & 0x0c100000) == 0x04100000) {
418 int reg = (instr >> 12) & 15;
419 unsigned long val;
420
421 if (instr & 0x00400000)
422 val = 255;
423 else
424 val = -1;
425
426 regs->uregs[reg] = val;
427 regs->ARM_pc += 4;
428 return 0;
429 }
430
431 if ((instr & 0x0e100090) == 0x00100090) {
432 int reg = (instr >> 12) & 15;
433
434 regs->uregs[reg] = -1;
435 regs->ARM_pc += 4;
436 return 0;
437 }
438
439 return 1;
440}
441
Jeff Garzike8f2af12007-10-26 05:40:25 -0400442static irqreturn_t v3_irq(int dummy, void *devid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443{
444#ifdef CONFIG_DEBUG_LL
Linus Torvalds0cd61b62006-10-06 10:53:39 -0700445 struct pt_regs *regs = get_irq_regs();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 unsigned long pc = instruction_pointer(regs);
447 unsigned long instr = *(unsigned long *)pc;
448 char buf[128];
Russell King7c284722008-05-23 19:35:52 +0100449 extern void printascii(const char *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450
Jeff Garzike8f2af12007-10-26 05:40:25 -0400451 sprintf(buf, "V3 int %d: pc=0x%08lx [%08lx] LBFADDR=%08x LBFCODE=%02x "
452 "ISTAT=%02x\n", IRQ_AP_V3INT, pc, instr,
Linus Walleij379df272012-11-17 19:24:23 +0100453 __raw_readl(ap_syscon_base + INTEGRATOR_SC_LBFADDR_OFFSET),
454 __raw_readl(ap_syscon_base + INTEGRATOR_SC_LBFCODE_OFFSET) & 255,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 v3_readb(V3_LB_ISTAT));
456 printascii(buf);
457#endif
458
459 v3_writew(V3_PCI_STAT, 0xf000);
460 v3_writeb(V3_LB_ISTAT, 0);
Linus Walleij379df272012-11-17 19:24:23 +0100461 __raw_writel(3, ap_syscon_base + INTEGRATOR_SC_PCIENABLE_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462
463#ifdef CONFIG_DEBUG_LL
464 /*
465 * If the instruction being executed was a read,
466 * make it look like it read all-ones.
467 */
468 if ((instr & 0x0c100000) == 0x04100000) {
469 int reg = (instr >> 16) & 15;
470 sprintf(buf, " reg%d = %08lx\n", reg, regs->uregs[reg]);
471 printascii(buf);
472 }
473#endif
474 return IRQ_HANDLED;
475}
476
477int __init pci_v3_setup(int nr, struct pci_sys_data *sys)
478{
479 int ret = 0;
480
481 if (nr == 0) {
482 sys->mem_offset = PHYS_PCI_MEM_BASE;
Bjorn Helgaas37d15902011-10-28 16:26:16 -0600483 ret = pci_v3_setup_resources(sys);
Linus Walleij379df272012-11-17 19:24:23 +0100484 /* Remap the Integrator system controller */
485 ap_syscon_base = ioremap(INTEGRATOR_SC_BASE, 0x100);
486 if (!ap_syscon_base)
487 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 }
489
490 return ret;
491}
492
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493/*
494 * V3_LB_BASE? - local bus address
495 * V3_LB_MAP? - pci bus address
496 */
497void __init pci_v3_preinit(void)
498{
499 unsigned long flags;
500 unsigned int temp;
501 int ret;
502
Rob Herringc9d95fb2011-06-28 21:16:13 -0500503 pcibios_min_mem = 0x00100000;
504
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 /*
506 * Hook in our fault handler for PCI errors
507 */
Kirill A. Shutemov6338a6a2010-07-22 13:18:19 +0100508 hook_fault_code(4, v3_pci_fault, SIGBUS, 0, "external abort on linefetch");
509 hook_fault_code(6, v3_pci_fault, SIGBUS, 0, "external abort on linefetch");
510 hook_fault_code(8, v3_pci_fault, SIGBUS, 0, "external abort on non-linefetch");
511 hook_fault_code(10, v3_pci_fault, SIGBUS, 0, "external abort on non-linefetch");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512
Thomas Gleixnerbd31b852009-07-03 08:44:46 -0500513 raw_spin_lock_irqsave(&v3_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514
515 /*
516 * Unlock V3 registers, but only if they were previously locked.
517 */
518 if (v3_readw(V3_SYSTEM) & V3_SYSTEM_M_LOCK)
519 v3_writew(V3_SYSTEM, 0xa05f);
520
521 /*
522 * Setup window 0 - PCI non-prefetchable memory
523 * Local: 0x40000000 Bus: 0x00000000 Size: 256MB
524 */
525 v3_writel(V3_LB_BASE0, v3_addr_to_lb_base(PHYS_PCI_MEM_BASE) |
526 V3_LB_BASE_ADR_SIZE_256MB | V3_LB_BASE_ENABLE);
527 v3_writew(V3_LB_MAP0, v3_addr_to_lb_map(PCI_BUS_NONMEM_START) |
528 V3_LB_MAP_TYPE_MEM);
529
530 /*
531 * Setup window 1 - PCI prefetchable memory
532 * Local: 0x50000000 Bus: 0x10000000 Size: 256MB
533 */
534 v3_writel(V3_LB_BASE1, v3_addr_to_lb_base(PHYS_PCI_MEM_BASE + SZ_256M) |
535 V3_LB_BASE_ADR_SIZE_256MB | V3_LB_BASE_PREFETCH |
536 V3_LB_BASE_ENABLE);
537 v3_writew(V3_LB_MAP1, v3_addr_to_lb_map(PCI_BUS_PREMEM_START) |
538 V3_LB_MAP_TYPE_MEM_MULTIPLE);
539
540 /*
541 * Setup window 2 - PCI IO
542 */
543 v3_writel(V3_LB_BASE2, v3_addr_to_lb_base2(PHYS_PCI_IO_BASE) |
544 V3_LB_BASE_ENABLE);
545 v3_writew(V3_LB_MAP2, v3_addr_to_lb_map2(0));
546
547 /*
548 * Disable PCI to host IO cycles
549 */
550 temp = v3_readw(V3_PCI_CFG) & ~V3_PCI_CFG_M_I2O_EN;
551 temp |= V3_PCI_CFG_M_IO_REG_DIS | V3_PCI_CFG_M_IO_DIS;
552 v3_writew(V3_PCI_CFG, temp);
553
554 printk(KERN_DEBUG "FIFO_CFG: %04x FIFO_PRIO: %04x\n",
555 v3_readw(V3_FIFO_CFG), v3_readw(V3_FIFO_PRIORITY));
556
557 /*
558 * Set the V3 FIFO such that writes have higher priority than
559 * reads, and local bus write causes local bus read fifo flush.
560 * Same for PCI.
561 */
562 v3_writew(V3_FIFO_PRIORITY, 0x0a0a);
563
564 /*
565 * Re-lock the system register.
566 */
567 temp = v3_readw(V3_SYSTEM) | V3_SYSTEM_M_LOCK;
568 v3_writew(V3_SYSTEM, temp);
569
570 /*
571 * Clear any error conditions, and enable write errors.
572 */
573 v3_writeb(V3_LB_ISTAT, 0);
574 v3_writew(V3_LB_CFG, v3_readw(V3_LB_CFG) | (1 << 10));
575 v3_writeb(V3_LB_IMASK, 0x28);
Linus Walleij379df272012-11-17 19:24:23 +0100576 __raw_writel(3, ap_syscon_base + INTEGRATOR_SC_PCIENABLE_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577
578 /*
579 * Grab the PCI error interrupt.
580 */
581 ret = request_irq(IRQ_AP_V3INT, v3_irq, 0, "V3", NULL);
582 if (ret)
583 printk(KERN_ERR "PCI: unable to grab PCI error "
584 "interrupt: %d\n", ret);
585
Thomas Gleixnerbd31b852009-07-03 08:44:46 -0500586 raw_spin_unlock_irqrestore(&v3_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587}
588
589void __init pci_v3_postinit(void)
590{
591 unsigned int pci_cmd;
592
593 pci_cmd = PCI_COMMAND_MEMORY |
594 PCI_COMMAND_MASTER | PCI_COMMAND_INVALIDATE;
595
596 v3_writew(V3_PCI_CMD, pci_cmd);
597
598 v3_writeb(V3_LB_ISTAT, ~0x40);
599 v3_writeb(V3_LB_IMASK, 0x68);
600
601#if 0
602 ret = request_irq(IRQ_AP_LBUSTIMEOUT, lb_timeout, 0, "bus timeout", NULL);
603 if (ret)
604 printk(KERN_ERR "PCI: unable to grab local bus timeout "
605 "interrupt: %d\n", ret);
606#endif
Russell King863dab42006-08-28 12:47:05 +0100607
608 register_isa_ports(PHYS_PCI_MEM_BASE, PHYS_PCI_IO_BASE, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609}