diff options
Diffstat (limited to 'arch/arm/mach-integrator/pci_v3.c')
-rw-r--r-- | arch/arm/mach-integrator/pci_v3.c | 564 |
1 files changed, 498 insertions, 66 deletions
diff --git a/arch/arm/mach-integrator/pci_v3.c b/arch/arm/mach-integrator/pci_v3.c index e7fcea7f3300..bef100527c42 100644 --- a/arch/arm/mach-integrator/pci_v3.c +++ b/arch/arm/mach-integrator/pci_v3.c | |||
@@ -27,16 +27,199 @@ | |||
27 | #include <linux/spinlock.h> | 27 | #include <linux/spinlock.h> |
28 | #include <linux/init.h> | 28 | #include <linux/init.h> |
29 | #include <linux/io.h> | 29 | #include <linux/io.h> |
30 | #include <linux/platform_device.h> | ||
31 | #include <linux/of.h> | ||
32 | #include <linux/of_address.h> | ||
33 | #include <linux/of_irq.h> | ||
34 | #include <linux/of_pci.h> | ||
35 | #include <video/vga.h> | ||
30 | 36 | ||
31 | #include <mach/hardware.h> | 37 | #include <mach/hardware.h> |
32 | #include <mach/platform.h> | 38 | #include <mach/platform.h> |
33 | #include <mach/irqs.h> | 39 | #include <mach/irqs.h> |
34 | 40 | ||
41 | #include <asm/mach/map.h> | ||
35 | #include <asm/signal.h> | 42 | #include <asm/signal.h> |
36 | #include <asm/mach/pci.h> | 43 | #include <asm/mach/pci.h> |
37 | #include <asm/irq_regs.h> | 44 | #include <asm/irq_regs.h> |
38 | 45 | ||
39 | #include <asm/hardware/pci_v3.h> | 46 | #include "pci_v3.h" |
47 | |||
48 | /* | ||
49 | * Where in the memory map does PCI live? | ||
50 | * | ||
51 | * This represents a fairly liberal usage of address space. Even though | ||
52 | * the V3 only has two windows (therefore we need to map stuff on the fly), | ||
53 | * we maintain the same addresses, even if they're not mapped. | ||
54 | */ | ||
55 | #define PHYS_PCI_MEM_BASE 0x40000000 /* 256M */ | ||
56 | #define PHYS_PCI_PRE_BASE 0x50000000 /* 256M */ | ||
57 | #define PHYS_PCI_IO_BASE 0x60000000 /* 16M */ | ||
58 | #define PHYS_PCI_CONFIG_BASE 0x61000000 /* 16M */ | ||
59 | #define PHYS_PCI_V3_BASE 0x62000000 /* 64K */ | ||
60 | |||
61 | #define PCI_MEMORY_VADDR IOMEM(0xe8000000) | ||
62 | #define PCI_CONFIG_VADDR IOMEM(0xec000000) | ||
63 | |||
64 | /* | ||
65 | * V3 Local Bus to PCI Bridge definitions | ||
66 | * | ||
67 | * Registers (these are taken from page 129 of the EPC User's Manual Rev 1.04 | ||
68 | * All V3 register names are prefaced by V3_ to avoid clashing with any other | ||
69 | * PCI definitions. Their names match the user's manual. | ||
70 | * | ||
71 | * I'm assuming that I20 is disabled. | ||
72 | * | ||
73 | */ | ||
74 | #define V3_PCI_VENDOR 0x00000000 | ||
75 | #define V3_PCI_DEVICE 0x00000002 | ||
76 | #define V3_PCI_CMD 0x00000004 | ||
77 | #define V3_PCI_STAT 0x00000006 | ||
78 | #define V3_PCI_CC_REV 0x00000008 | ||
79 | #define V3_PCI_HDR_CFG 0x0000000C | ||
80 | #define V3_PCI_IO_BASE 0x00000010 | ||
81 | #define V3_PCI_BASE0 0x00000014 | ||
82 | #define V3_PCI_BASE1 0x00000018 | ||
83 | #define V3_PCI_SUB_VENDOR 0x0000002C | ||
84 | #define V3_PCI_SUB_ID 0x0000002E | ||
85 | #define V3_PCI_ROM 0x00000030 | ||
86 | #define V3_PCI_BPARAM 0x0000003C | ||
87 | #define V3_PCI_MAP0 0x00000040 | ||
88 | #define V3_PCI_MAP1 0x00000044 | ||
89 | #define V3_PCI_INT_STAT 0x00000048 | ||
90 | #define V3_PCI_INT_CFG 0x0000004C | ||
91 | #define V3_LB_BASE0 0x00000054 | ||
92 | #define V3_LB_BASE1 0x00000058 | ||
93 | #define V3_LB_MAP0 0x0000005E | ||
94 | #define V3_LB_MAP1 0x00000062 | ||
95 | #define V3_LB_BASE2 0x00000064 | ||
96 | #define V3_LB_MAP2 0x00000066 | ||
97 | #define V3_LB_SIZE 0x00000068 | ||
98 | #define V3_LB_IO_BASE 0x0000006E | ||
99 | #define V3_FIFO_CFG 0x00000070 | ||
100 | #define V3_FIFO_PRIORITY 0x00000072 | ||
101 | #define V3_FIFO_STAT 0x00000074 | ||
102 | #define V3_LB_ISTAT 0x00000076 | ||
103 | #define V3_LB_IMASK 0x00000077 | ||
104 | #define V3_SYSTEM 0x00000078 | ||
105 | #define V3_LB_CFG 0x0000007A | ||
106 | #define V3_PCI_CFG 0x0000007C | ||
107 | #define V3_DMA_PCI_ADR0 0x00000080 | ||
108 | #define V3_DMA_PCI_ADR1 0x00000090 | ||
109 | #define V3_DMA_LOCAL_ADR0 0x00000084 | ||
110 | #define V3_DMA_LOCAL_ADR1 0x00000094 | ||
111 | #define V3_DMA_LENGTH0 0x00000088 | ||
112 | #define V3_DMA_LENGTH1 0x00000098 | ||
113 | #define V3_DMA_CSR0 0x0000008B | ||
114 | #define V3_DMA_CSR1 0x0000009B | ||
115 | #define V3_DMA_CTLB_ADR0 0x0000008C | ||
116 | #define V3_DMA_CTLB_ADR1 0x0000009C | ||
117 | #define V3_DMA_DELAY 0x000000E0 | ||
118 | #define V3_MAIL_DATA 0x000000C0 | ||
119 | #define V3_PCI_MAIL_IEWR 0x000000D0 | ||
120 | #define V3_PCI_MAIL_IERD 0x000000D2 | ||
121 | #define V3_LB_MAIL_IEWR 0x000000D4 | ||
122 | #define V3_LB_MAIL_IERD 0x000000D6 | ||
123 | #define V3_MAIL_WR_STAT 0x000000D8 | ||
124 | #define V3_MAIL_RD_STAT 0x000000DA | ||
125 | #define V3_QBA_MAP 0x000000DC | ||
126 | |||
127 | /* PCI COMMAND REGISTER bits | ||
128 | */ | ||
129 | #define V3_COMMAND_M_FBB_EN (1 << 9) | ||
130 | #define V3_COMMAND_M_SERR_EN (1 << 8) | ||
131 | #define V3_COMMAND_M_PAR_EN (1 << 6) | ||
132 | #define V3_COMMAND_M_MASTER_EN (1 << 2) | ||
133 | #define V3_COMMAND_M_MEM_EN (1 << 1) | ||
134 | #define V3_COMMAND_M_IO_EN (1 << 0) | ||
135 | |||
136 | /* SYSTEM REGISTER bits | ||
137 | */ | ||
138 | #define V3_SYSTEM_M_RST_OUT (1 << 15) | ||
139 | #define V3_SYSTEM_M_LOCK (1 << 14) | ||
140 | |||
141 | /* PCI_CFG bits | ||
142 | */ | ||
143 | #define V3_PCI_CFG_M_I2O_EN (1 << 15) | ||
144 | #define V3_PCI_CFG_M_IO_REG_DIS (1 << 14) | ||
145 | #define V3_PCI_CFG_M_IO_DIS (1 << 13) | ||
146 | #define V3_PCI_CFG_M_EN3V (1 << 12) | ||
147 | #define V3_PCI_CFG_M_RETRY_EN (1 << 10) | ||
148 | #define V3_PCI_CFG_M_AD_LOW1 (1 << 9) | ||
149 | #define V3_PCI_CFG_M_AD_LOW0 (1 << 8) | ||
150 | |||
151 | /* PCI_BASE register bits (PCI -> Local Bus) | ||
152 | */ | ||
153 | #define V3_PCI_BASE_M_ADR_BASE 0xFFF00000 | ||
154 | #define V3_PCI_BASE_M_ADR_BASEL 0x000FFF00 | ||
155 | #define V3_PCI_BASE_M_PREFETCH (1 << 3) | ||
156 | #define V3_PCI_BASE_M_TYPE (3 << 1) | ||
157 | #define V3_PCI_BASE_M_IO (1 << 0) | ||
158 | |||
159 | /* PCI MAP register bits (PCI -> Local bus) | ||
160 | */ | ||
161 | #define V3_PCI_MAP_M_MAP_ADR 0xFFF00000 | ||
162 | #define V3_PCI_MAP_M_RD_POST_INH (1 << 15) | ||
163 | #define V3_PCI_MAP_M_ROM_SIZE (3 << 10) | ||
164 | #define V3_PCI_MAP_M_SWAP (3 << 8) | ||
165 | #define V3_PCI_MAP_M_ADR_SIZE 0x000000F0 | ||
166 | #define V3_PCI_MAP_M_REG_EN (1 << 1) | ||
167 | #define V3_PCI_MAP_M_ENABLE (1 << 0) | ||
168 | |||
169 | /* | ||
170 | * LB_BASE0,1 register bits (Local bus -> PCI) | ||
171 | */ | ||
172 | #define V3_LB_BASE_ADR_BASE 0xfff00000 | ||
173 | #define V3_LB_BASE_SWAP (3 << 8) | ||
174 | #define V3_LB_BASE_ADR_SIZE (15 << 4) | ||
175 | #define V3_LB_BASE_PREFETCH (1 << 3) | ||
176 | #define V3_LB_BASE_ENABLE (1 << 0) | ||
177 | |||
178 | #define V3_LB_BASE_ADR_SIZE_1MB (0 << 4) | ||
179 | #define V3_LB_BASE_ADR_SIZE_2MB (1 << 4) | ||
180 | #define V3_LB_BASE_ADR_SIZE_4MB (2 << 4) | ||
181 | #define V3_LB_BASE_ADR_SIZE_8MB (3 << 4) | ||
182 | #define V3_LB_BASE_ADR_SIZE_16MB (4 << 4) | ||
183 | #define V3_LB_BASE_ADR_SIZE_32MB (5 << 4) | ||
184 | #define V3_LB_BASE_ADR_SIZE_64MB (6 << 4) | ||
185 | #define V3_LB_BASE_ADR_SIZE_128MB (7 << 4) | ||
186 | #define V3_LB_BASE_ADR_SIZE_256MB (8 << 4) | ||
187 | #define V3_LB_BASE_ADR_SIZE_512MB (9 << 4) | ||
188 | #define V3_LB_BASE_ADR_SIZE_1GB (10 << 4) | ||
189 | #define V3_LB_BASE_ADR_SIZE_2GB (11 << 4) | ||
190 | |||
191 | #define v3_addr_to_lb_base(a) ((a) & V3_LB_BASE_ADR_BASE) | ||
192 | |||
193 | /* | ||
194 | * LB_MAP0,1 register bits (Local bus -> PCI) | ||
195 | */ | ||
196 | #define V3_LB_MAP_MAP_ADR 0xfff0 | ||
197 | #define V3_LB_MAP_TYPE (7 << 1) | ||
198 | #define V3_LB_MAP_AD_LOW_EN (1 << 0) | ||
199 | |||
200 | #define V3_LB_MAP_TYPE_IACK (0 << 1) | ||
201 | #define V3_LB_MAP_TYPE_IO (1 << 1) | ||
202 | #define V3_LB_MAP_TYPE_MEM (3 << 1) | ||
203 | #define V3_LB_MAP_TYPE_CONFIG (5 << 1) | ||
204 | #define V3_LB_MAP_TYPE_MEM_MULTIPLE (6 << 1) | ||
205 | |||
206 | #define v3_addr_to_lb_map(a) (((a) >> 16) & V3_LB_MAP_MAP_ADR) | ||
207 | |||
208 | /* | ||
209 | * LB_BASE2 register bits (Local bus -> PCI IO) | ||
210 | */ | ||
211 | #define V3_LB_BASE2_ADR_BASE 0xff00 | ||
212 | #define V3_LB_BASE2_SWAP (3 << 6) | ||
213 | #define V3_LB_BASE2_ENABLE (1 << 0) | ||
214 | |||
215 | #define v3_addr_to_lb_base2(a) (((a) >> 16) & V3_LB_BASE2_ADR_BASE) | ||
216 | |||
217 | /* | ||
218 | * LB_MAP2 register bits (Local bus -> PCI IO) | ||
219 | */ | ||
220 | #define V3_LB_MAP2_MAP_ADR 0xff00 | ||
221 | |||
222 | #define v3_addr_to_lb_map2(a) (((a) >> 16) & V3_LB_MAP2_MAP_ADR) | ||
40 | 223 | ||
41 | /* | 224 | /* |
42 | * The V3 PCI interface chip in Integrator provides several windows from | 225 | * The V3 PCI interface chip in Integrator provides several windows from |
@@ -101,15 +284,28 @@ | |||
101 | * the mappings into PCI memory. | 284 | * the mappings into PCI memory. |
102 | */ | 285 | */ |
103 | 286 | ||
287 | /* Filled in by probe */ | ||
288 | static void __iomem *pci_v3_base; | ||
289 | /* CPU side memory ranges */ | ||
290 | static struct resource conf_mem; /* FIXME: remap this instead of static map */ | ||
291 | static struct resource io_mem; | ||
292 | static struct resource non_mem; | ||
293 | static struct resource pre_mem; | ||
294 | /* PCI side memory ranges */ | ||
295 | static u64 non_mem_pci; | ||
296 | static u64 non_mem_pci_sz; | ||
297 | static u64 pre_mem_pci; | ||
298 | static u64 pre_mem_pci_sz; | ||
299 | |||
104 | // V3 access routines | 300 | // V3 access routines |
105 | #define v3_writeb(o,v) __raw_writeb(v, PCI_V3_VADDR + (unsigned int)(o)) | 301 | #define v3_writeb(o,v) __raw_writeb(v, pci_v3_base + (unsigned int)(o)) |
106 | #define v3_readb(o) (__raw_readb(PCI_V3_VADDR + (unsigned int)(o))) | 302 | #define v3_readb(o) (__raw_readb(pci_v3_base + (unsigned int)(o))) |
107 | 303 | ||
108 | #define v3_writew(o,v) __raw_writew(v, PCI_V3_VADDR + (unsigned int)(o)) | 304 | #define v3_writew(o,v) __raw_writew(v, pci_v3_base + (unsigned int)(o)) |
109 | #define v3_readw(o) (__raw_readw(PCI_V3_VADDR + (unsigned int)(o))) | 305 | #define v3_readw(o) (__raw_readw(pci_v3_base + (unsigned int)(o))) |
110 | 306 | ||
111 | #define v3_writel(o,v) __raw_writel(v, PCI_V3_VADDR + (unsigned int)(o)) | 307 | #define v3_writel(o,v) __raw_writel(v, pci_v3_base + (unsigned int)(o)) |
112 | #define v3_readl(o) (__raw_readl(PCI_V3_VADDR + (unsigned int)(o))) | 308 | #define v3_readl(o) (__raw_readl(pci_v3_base + (unsigned int)(o))) |
113 | 309 | ||
114 | /*============================================================================ | 310 | /*============================================================================ |
115 | * | 311 | * |
@@ -165,19 +361,6 @@ | |||
165 | */ | 361 | */ |
166 | static DEFINE_RAW_SPINLOCK(v3_lock); | 362 | static DEFINE_RAW_SPINLOCK(v3_lock); |
167 | 363 | ||
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 | 364 | #undef V3_LB_BASE_PREFETCH |
182 | #define V3_LB_BASE_PREFETCH 0 | 365 | #define V3_LB_BASE_PREFETCH 0 |
183 | 366 | ||
@@ -243,13 +426,13 @@ static void __iomem *v3_open_config_window(struct pci_bus *bus, | |||
243 | * prefetchable), this frees up base1 for re-use by | 426 | * prefetchable), this frees up base1 for re-use by |
244 | * configuration memory | 427 | * configuration memory |
245 | */ | 428 | */ |
246 | v3_writel(V3_LB_BASE0, v3_addr_to_lb_base(PHYS_PCI_MEM_BASE) | | 429 | v3_writel(V3_LB_BASE0, v3_addr_to_lb_base(non_mem.start) | |
247 | V3_LB_BASE_ADR_SIZE_512MB | V3_LB_BASE_ENABLE); | 430 | V3_LB_BASE_ADR_SIZE_512MB | V3_LB_BASE_ENABLE); |
248 | 431 | ||
249 | /* | 432 | /* |
250 | * Set up base1/map1 to point into configuration space. | 433 | * Set up base1/map1 to point into configuration space. |
251 | */ | 434 | */ |
252 | v3_writel(V3_LB_BASE1, v3_addr_to_lb_base(PHYS_PCI_CONFIG_BASE) | | 435 | v3_writel(V3_LB_BASE1, v3_addr_to_lb_base(conf_mem.start) | |
253 | V3_LB_BASE_ADR_SIZE_16MB | V3_LB_BASE_ENABLE); | 436 | V3_LB_BASE_ADR_SIZE_16MB | V3_LB_BASE_ENABLE); |
254 | v3_writew(V3_LB_MAP1, mapaddress); | 437 | v3_writew(V3_LB_MAP1, mapaddress); |
255 | 438 | ||
@@ -261,16 +444,16 @@ static void v3_close_config_window(void) | |||
261 | /* | 444 | /* |
262 | * Reassign base1 for use by prefetchable PCI memory | 445 | * Reassign base1 for use by prefetchable PCI memory |
263 | */ | 446 | */ |
264 | v3_writel(V3_LB_BASE1, v3_addr_to_lb_base(PHYS_PCI_MEM_BASE + SZ_256M) | | 447 | v3_writel(V3_LB_BASE1, v3_addr_to_lb_base(pre_mem.start) | |
265 | V3_LB_BASE_ADR_SIZE_256MB | V3_LB_BASE_PREFETCH | | 448 | V3_LB_BASE_ADR_SIZE_256MB | V3_LB_BASE_PREFETCH | |
266 | V3_LB_BASE_ENABLE); | 449 | V3_LB_BASE_ENABLE); |
267 | v3_writew(V3_LB_MAP1, v3_addr_to_lb_map(PCI_BUS_PREMEM_START) | | 450 | v3_writew(V3_LB_MAP1, v3_addr_to_lb_map(pre_mem_pci) | |
268 | V3_LB_MAP_TYPE_MEM_MULTIPLE); | 451 | V3_LB_MAP_TYPE_MEM_MULTIPLE); |
269 | 452 | ||
270 | /* | 453 | /* |
271 | * And shrink base0 back to a 256M window (NOTE: MAP0 already correct) | 454 | * And shrink base0 back to a 256M window (NOTE: MAP0 already correct) |
272 | */ | 455 | */ |
273 | v3_writel(V3_LB_BASE0, v3_addr_to_lb_base(PHYS_PCI_MEM_BASE) | | 456 | v3_writel(V3_LB_BASE0, v3_addr_to_lb_base(non_mem.start) | |
274 | V3_LB_BASE_ADR_SIZE_256MB | V3_LB_BASE_ENABLE); | 457 | V3_LB_BASE_ADR_SIZE_256MB | V3_LB_BASE_ENABLE); |
275 | } | 458 | } |
276 | 459 | ||
@@ -337,25 +520,11 @@ static int v3_write_config(struct pci_bus *bus, unsigned int devfn, int where, | |||
337 | return PCIBIOS_SUCCESSFUL; | 520 | return PCIBIOS_SUCCESSFUL; |
338 | } | 521 | } |
339 | 522 | ||
340 | struct pci_ops pci_v3_ops = { | 523 | static struct pci_ops pci_v3_ops = { |
341 | .read = v3_read_config, | 524 | .read = v3_read_config, |
342 | .write = v3_write_config, | 525 | .write = v3_write_config, |
343 | }; | 526 | }; |
344 | 527 | ||
345 | static struct resource non_mem = { | ||
346 | .name = "PCI non-prefetchable", | ||
347 | .start = PHYS_PCI_MEM_BASE + PCI_BUS_NONMEM_START, | ||
348 | .end = PHYS_PCI_MEM_BASE + PCI_BUS_NONMEM_START + PCI_BUS_NONMEM_SIZE - 1, | ||
349 | .flags = IORESOURCE_MEM, | ||
350 | }; | ||
351 | |||
352 | static struct resource pre_mem = { | ||
353 | .name = "PCI prefetchable", | ||
354 | .start = PHYS_PCI_MEM_BASE + PCI_BUS_PREMEM_START, | ||
355 | .end = PHYS_PCI_MEM_BASE + PCI_BUS_PREMEM_START + PCI_BUS_PREMEM_SIZE - 1, | ||
356 | .flags = IORESOURCE_MEM | IORESOURCE_PREFETCH, | ||
357 | }; | ||
358 | |||
359 | static int __init pci_v3_setup_resources(struct pci_sys_data *sys) | 528 | static int __init pci_v3_setup_resources(struct pci_sys_data *sys) |
360 | { | 529 | { |
361 | if (request_resource(&iomem_resource, &non_mem)) { | 530 | if (request_resource(&iomem_resource, &non_mem)) { |
@@ -471,7 +640,7 @@ static irqreturn_t v3_irq(int dummy, void *devid) | |||
471 | return IRQ_HANDLED; | 640 | return IRQ_HANDLED; |
472 | } | 641 | } |
473 | 642 | ||
474 | int __init pci_v3_setup(int nr, struct pci_sys_data *sys) | 643 | static int __init pci_v3_setup(int nr, struct pci_sys_data *sys) |
475 | { | 644 | { |
476 | int ret = 0; | 645 | int ret = 0; |
477 | 646 | ||
@@ -479,7 +648,7 @@ int __init pci_v3_setup(int nr, struct pci_sys_data *sys) | |||
479 | return -EINVAL; | 648 | return -EINVAL; |
480 | 649 | ||
481 | if (nr == 0) { | 650 | if (nr == 0) { |
482 | sys->mem_offset = PHYS_PCI_MEM_BASE; | 651 | sys->mem_offset = non_mem.start; |
483 | ret = pci_v3_setup_resources(sys); | 652 | ret = pci_v3_setup_resources(sys); |
484 | } | 653 | } |
485 | 654 | ||
@@ -490,18 +659,10 @@ int __init pci_v3_setup(int nr, struct pci_sys_data *sys) | |||
490 | * V3_LB_BASE? - local bus address | 659 | * V3_LB_BASE? - local bus address |
491 | * V3_LB_MAP? - pci bus address | 660 | * V3_LB_MAP? - pci bus address |
492 | */ | 661 | */ |
493 | void __init pci_v3_preinit(void) | 662 | static void __init pci_v3_preinit(void) |
494 | { | 663 | { |
495 | unsigned long flags; | 664 | unsigned long flags; |
496 | unsigned int temp; | 665 | unsigned int temp; |
497 | int ret; | ||
498 | |||
499 | /* Remap the Integrator system controller */ | ||
500 | ap_syscon_base = ioremap(INTEGRATOR_SC_BASE, 0x100); | ||
501 | if (!ap_syscon_base) { | ||
502 | pr_err("unable to remap the AP syscon for PCIv3\n"); | ||
503 | return; | ||
504 | } | ||
505 | 666 | ||
506 | pcibios_min_mem = 0x00100000; | 667 | pcibios_min_mem = 0x00100000; |
507 | 668 | ||
@@ -525,25 +686,25 @@ void __init pci_v3_preinit(void) | |||
525 | * Setup window 0 - PCI non-prefetchable memory | 686 | * Setup window 0 - PCI non-prefetchable memory |
526 | * Local: 0x40000000 Bus: 0x00000000 Size: 256MB | 687 | * Local: 0x40000000 Bus: 0x00000000 Size: 256MB |
527 | */ | 688 | */ |
528 | v3_writel(V3_LB_BASE0, v3_addr_to_lb_base(PHYS_PCI_MEM_BASE) | | 689 | v3_writel(V3_LB_BASE0, v3_addr_to_lb_base(non_mem.start) | |
529 | V3_LB_BASE_ADR_SIZE_256MB | V3_LB_BASE_ENABLE); | 690 | V3_LB_BASE_ADR_SIZE_256MB | V3_LB_BASE_ENABLE); |
530 | v3_writew(V3_LB_MAP0, v3_addr_to_lb_map(PCI_BUS_NONMEM_START) | | 691 | v3_writew(V3_LB_MAP0, v3_addr_to_lb_map(non_mem_pci) | |
531 | V3_LB_MAP_TYPE_MEM); | 692 | V3_LB_MAP_TYPE_MEM); |
532 | 693 | ||
533 | /* | 694 | /* |
534 | * Setup window 1 - PCI prefetchable memory | 695 | * Setup window 1 - PCI prefetchable memory |
535 | * Local: 0x50000000 Bus: 0x10000000 Size: 256MB | 696 | * Local: 0x50000000 Bus: 0x10000000 Size: 256MB |
536 | */ | 697 | */ |
537 | v3_writel(V3_LB_BASE1, v3_addr_to_lb_base(PHYS_PCI_MEM_BASE + SZ_256M) | | 698 | v3_writel(V3_LB_BASE1, v3_addr_to_lb_base(pre_mem.start) | |
538 | V3_LB_BASE_ADR_SIZE_256MB | V3_LB_BASE_PREFETCH | | 699 | V3_LB_BASE_ADR_SIZE_256MB | V3_LB_BASE_PREFETCH | |
539 | V3_LB_BASE_ENABLE); | 700 | V3_LB_BASE_ENABLE); |
540 | v3_writew(V3_LB_MAP1, v3_addr_to_lb_map(PCI_BUS_PREMEM_START) | | 701 | v3_writew(V3_LB_MAP1, v3_addr_to_lb_map(pre_mem_pci) | |
541 | V3_LB_MAP_TYPE_MEM_MULTIPLE); | 702 | V3_LB_MAP_TYPE_MEM_MULTIPLE); |
542 | 703 | ||
543 | /* | 704 | /* |
544 | * Setup window 2 - PCI IO | 705 | * Setup window 2 - PCI IO |
545 | */ | 706 | */ |
546 | v3_writel(V3_LB_BASE2, v3_addr_to_lb_base2(PHYS_PCI_IO_BASE) | | 707 | v3_writel(V3_LB_BASE2, v3_addr_to_lb_base2(io_mem.start) | |
547 | V3_LB_BASE_ENABLE); | 708 | V3_LB_BASE_ENABLE); |
548 | v3_writew(V3_LB_MAP2, v3_addr_to_lb_map2(0)); | 709 | v3_writew(V3_LB_MAP2, v3_addr_to_lb_map2(0)); |
549 | 710 | ||
@@ -578,18 +739,10 @@ void __init pci_v3_preinit(void) | |||
578 | v3_writeb(V3_LB_IMASK, 0x28); | 739 | v3_writeb(V3_LB_IMASK, 0x28); |
579 | __raw_writel(3, ap_syscon_base + INTEGRATOR_SC_PCIENABLE_OFFSET); | 740 | __raw_writel(3, ap_syscon_base + INTEGRATOR_SC_PCIENABLE_OFFSET); |
580 | 741 | ||
581 | /* | ||
582 | * Grab the PCI error interrupt. | ||
583 | */ | ||
584 | ret = request_irq(IRQ_AP_V3INT, v3_irq, 0, "V3", NULL); | ||
585 | if (ret) | ||
586 | printk(KERN_ERR "PCI: unable to grab PCI error " | ||
587 | "interrupt: %d\n", ret); | ||
588 | |||
589 | raw_spin_unlock_irqrestore(&v3_lock, flags); | 742 | raw_spin_unlock_irqrestore(&v3_lock, flags); |
590 | } | 743 | } |
591 | 744 | ||
592 | void __init pci_v3_postinit(void) | 745 | static void __init pci_v3_postinit(void) |
593 | { | 746 | { |
594 | unsigned int pci_cmd; | 747 | unsigned int pci_cmd; |
595 | 748 | ||
@@ -608,5 +761,284 @@ void __init pci_v3_postinit(void) | |||
608 | "interrupt: %d\n", ret); | 761 | "interrupt: %d\n", ret); |
609 | #endif | 762 | #endif |
610 | 763 | ||
611 | register_isa_ports(PHYS_PCI_MEM_BASE, PHYS_PCI_IO_BASE, 0); | 764 | register_isa_ports(non_mem.start, io_mem.start, 0); |
765 | } | ||
766 | |||
767 | /* | ||
768 | * A small note about bridges and interrupts. The DECchip 21050 (and | ||
769 | * later) adheres to the PCI-PCI bridge specification. This says that | ||
770 | * the interrupts on the other side of a bridge are swizzled in the | ||
771 | * following manner: | ||
772 | * | ||
773 | * Dev Interrupt Interrupt | ||
774 | * Pin on Pin on | ||
775 | * Device Connector | ||
776 | * | ||
777 | * 4 A A | ||
778 | * B B | ||
779 | * C C | ||
780 | * D D | ||
781 | * | ||
782 | * 5 A B | ||
783 | * B C | ||
784 | * C D | ||
785 | * D A | ||
786 | * | ||
787 | * 6 A C | ||
788 | * B D | ||
789 | * C A | ||
790 | * D B | ||
791 | * | ||
792 | * 7 A D | ||
793 | * B A | ||
794 | * C B | ||
795 | * D C | ||
796 | * | ||
797 | * Where A = pin 1, B = pin 2 and so on and pin=0 = default = A. | ||
798 | * Thus, each swizzle is ((pin-1) + (device#-4)) % 4 | ||
799 | */ | ||
800 | |||
801 | /* | ||
802 | * This routine handles multiple bridges. | ||
803 | */ | ||
804 | static u8 __init pci_v3_swizzle(struct pci_dev *dev, u8 *pinp) | ||
805 | { | ||
806 | if (*pinp == 0) | ||
807 | *pinp = 1; | ||
808 | |||
809 | return pci_common_swizzle(dev, pinp); | ||
810 | } | ||
811 | |||
812 | static int irq_tab[4] __initdata = { | ||
813 | IRQ_AP_PCIINT0, IRQ_AP_PCIINT1, IRQ_AP_PCIINT2, IRQ_AP_PCIINT3 | ||
814 | }; | ||
815 | |||
816 | /* | ||
817 | * map the specified device/slot/pin to an IRQ. This works out such | ||
818 | * that slot 9 pin 1 is INT0, pin 2 is INT1, and slot 10 pin 1 is INT1. | ||
819 | */ | ||
820 | static int __init pci_v3_map_irq(const struct pci_dev *dev, u8 slot, u8 pin) | ||
821 | { | ||
822 | int intnr = ((slot - 9) + (pin - 1)) & 3; | ||
823 | |||
824 | return irq_tab[intnr]; | ||
825 | } | ||
826 | |||
827 | static struct hw_pci pci_v3 __initdata = { | ||
828 | .swizzle = pci_v3_swizzle, | ||
829 | .setup = pci_v3_setup, | ||
830 | .nr_controllers = 1, | ||
831 | .ops = &pci_v3_ops, | ||
832 | .preinit = pci_v3_preinit, | ||
833 | .postinit = pci_v3_postinit, | ||
834 | }; | ||
835 | |||
836 | #ifdef CONFIG_OF | ||
837 | |||
838 | static int __init pci_v3_map_irq_dt(const struct pci_dev *dev, u8 slot, u8 pin) | ||
839 | { | ||
840 | struct of_irq oirq; | ||
841 | int ret; | ||
842 | |||
843 | ret = of_irq_map_pci(dev, &oirq); | ||
844 | if (ret) { | ||
845 | dev_err(&dev->dev, "of_irq_map_pci() %d\n", ret); | ||
846 | /* Proper return code 0 == NO_IRQ */ | ||
847 | return 0; | ||
848 | } | ||
849 | |||
850 | return irq_create_of_mapping(oirq.controller, oirq.specifier, | ||
851 | oirq.size); | ||
852 | } | ||
853 | |||
854 | static int __init pci_v3_dtprobe(struct platform_device *pdev, | ||
855 | struct device_node *np) | ||
856 | { | ||
857 | struct of_pci_range_parser parser; | ||
858 | struct of_pci_range range; | ||
859 | struct resource *res; | ||
860 | int irq, ret; | ||
861 | |||
862 | if (of_pci_range_parser_init(&parser, np)) | ||
863 | return -EINVAL; | ||
864 | |||
865 | /* Get base for bridge registers */ | ||
866 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
867 | if (!res) { | ||
868 | dev_err(&pdev->dev, "unable to obtain PCIv3 base\n"); | ||
869 | return -ENODEV; | ||
870 | } | ||
871 | pci_v3_base = devm_ioremap(&pdev->dev, res->start, | ||
872 | resource_size(res)); | ||
873 | if (!pci_v3_base) { | ||
874 | dev_err(&pdev->dev, "unable to remap PCIv3 base\n"); | ||
875 | return -ENODEV; | ||
876 | } | ||
877 | |||
878 | /* Get and request error IRQ resource */ | ||
879 | irq = platform_get_irq(pdev, 0); | ||
880 | if (irq <= 0) { | ||
881 | dev_err(&pdev->dev, "unable to obtain PCIv3 error IRQ\n"); | ||
882 | return -ENODEV; | ||
883 | } | ||
884 | ret = devm_request_irq(&pdev->dev, irq, v3_irq, 0, | ||
885 | "PCIv3 error", NULL); | ||
886 | if (ret < 0) { | ||
887 | dev_err(&pdev->dev, "unable to request PCIv3 error IRQ %d (%d)\n", irq, ret); | ||
888 | return ret; | ||
889 | } | ||
890 | |||
891 | for_each_of_pci_range(&parser, &range) { | ||
892 | if (!range.flags) { | ||
893 | of_pci_range_to_resource(&range, np, &conf_mem); | ||
894 | conf_mem.name = "PCIv3 config"; | ||
895 | } | ||
896 | if (range.flags & IORESOURCE_IO) { | ||
897 | of_pci_range_to_resource(&range, np, &io_mem); | ||
898 | io_mem.name = "PCIv3 I/O"; | ||
899 | } | ||
900 | if ((range.flags & IORESOURCE_MEM) && | ||
901 | !(range.flags & IORESOURCE_PREFETCH)) { | ||
902 | non_mem_pci = range.pci_addr; | ||
903 | non_mem_pci_sz = range.size; | ||
904 | of_pci_range_to_resource(&range, np, &non_mem); | ||
905 | non_mem.name = "PCIv3 non-prefetched mem"; | ||
906 | } | ||
907 | if ((range.flags & IORESOURCE_MEM) && | ||
908 | (range.flags & IORESOURCE_PREFETCH)) { | ||
909 | pre_mem_pci = range.pci_addr; | ||
910 | pre_mem_pci_sz = range.size; | ||
911 | of_pci_range_to_resource(&range, np, &pre_mem); | ||
912 | pre_mem.name = "PCIv3 prefetched mem"; | ||
913 | } | ||
914 | } | ||
915 | |||
916 | if (!conf_mem.start || !io_mem.start || | ||
917 | !non_mem.start || !pre_mem.start) { | ||
918 | dev_err(&pdev->dev, "missing ranges in device node\n"); | ||
919 | return -EINVAL; | ||
920 | } | ||
921 | |||
922 | pci_v3.map_irq = pci_v3_map_irq_dt; | ||
923 | pci_common_init_dev(&pdev->dev, &pci_v3); | ||
924 | |||
925 | return 0; | ||
926 | } | ||
927 | |||
928 | #else | ||
929 | |||
930 | static inline int pci_v3_dtprobe(struct platform_device *pdev, | ||
931 | struct device_node *np) | ||
932 | { | ||
933 | return -EINVAL; | ||
934 | } | ||
935 | |||
936 | #endif | ||
937 | |||
938 | static int __init pci_v3_probe(struct platform_device *pdev) | ||
939 | { | ||
940 | struct device_node *np = pdev->dev.of_node; | ||
941 | int ret; | ||
942 | |||
943 | /* Remap the Integrator system controller */ | ||
944 | ap_syscon_base = ioremap(INTEGRATOR_SC_BASE, 0x100); | ||
945 | if (!ap_syscon_base) { | ||
946 | dev_err(&pdev->dev, "unable to remap the AP syscon for PCIv3\n"); | ||
947 | return -ENODEV; | ||
948 | } | ||
949 | |||
950 | /* Device tree probe path */ | ||
951 | if (np) | ||
952 | return pci_v3_dtprobe(pdev, np); | ||
953 | |||
954 | pci_v3_base = devm_ioremap(&pdev->dev, PHYS_PCI_V3_BASE, SZ_64K); | ||
955 | if (!pci_v3_base) { | ||
956 | dev_err(&pdev->dev, "unable to remap PCIv3 base\n"); | ||
957 | return -ENODEV; | ||
958 | } | ||
959 | |||
960 | ret = devm_request_irq(&pdev->dev, IRQ_AP_V3INT, v3_irq, 0, "V3", NULL); | ||
961 | if (ret) { | ||
962 | dev_err(&pdev->dev, "unable to grab PCI error interrupt: %d\n", | ||
963 | ret); | ||
964 | return -ENODEV; | ||
965 | } | ||
966 | |||
967 | conf_mem.name = "PCIv3 config"; | ||
968 | conf_mem.start = PHYS_PCI_CONFIG_BASE; | ||
969 | conf_mem.end = PHYS_PCI_CONFIG_BASE + SZ_16M - 1; | ||
970 | conf_mem.flags = IORESOURCE_MEM; | ||
971 | |||
972 | io_mem.name = "PCIv3 I/O"; | ||
973 | io_mem.start = PHYS_PCI_IO_BASE; | ||
974 | io_mem.end = PHYS_PCI_IO_BASE + SZ_16M - 1; | ||
975 | io_mem.flags = IORESOURCE_MEM; | ||
976 | |||
977 | non_mem_pci = 0x00000000; | ||
978 | non_mem_pci_sz = SZ_256M; | ||
979 | non_mem.name = "PCIv3 non-prefetched mem"; | ||
980 | non_mem.start = PHYS_PCI_MEM_BASE; | ||
981 | non_mem.end = PHYS_PCI_MEM_BASE + SZ_256M - 1; | ||
982 | non_mem.flags = IORESOURCE_MEM; | ||
983 | |||
984 | pre_mem_pci = 0x10000000; | ||
985 | pre_mem_pci_sz = SZ_256M; | ||
986 | pre_mem.name = "PCIv3 prefetched mem"; | ||
987 | pre_mem.start = PHYS_PCI_PRE_BASE + SZ_256M; | ||
988 | pre_mem.end = PHYS_PCI_PRE_BASE + SZ_256M - 1; | ||
989 | pre_mem.flags = IORESOURCE_MEM | IORESOURCE_PREFETCH; | ||
990 | |||
991 | pci_v3.map_irq = pci_v3_map_irq; | ||
992 | |||
993 | pci_common_init_dev(&pdev->dev, &pci_v3); | ||
994 | |||
995 | return 0; | ||
996 | } | ||
997 | |||
998 | static const struct of_device_id pci_ids[] = { | ||
999 | { .compatible = "v3,v360epc-pci", }, | ||
1000 | {}, | ||
1001 | }; | ||
1002 | |||
1003 | static struct platform_driver pci_v3_driver = { | ||
1004 | .driver = { | ||
1005 | .name = "pci-v3", | ||
1006 | .of_match_table = pci_ids, | ||
1007 | }, | ||
1008 | }; | ||
1009 | |||
1010 | static int __init pci_v3_init(void) | ||
1011 | { | ||
1012 | return platform_driver_probe(&pci_v3_driver, pci_v3_probe); | ||
1013 | } | ||
1014 | |||
1015 | subsys_initcall(pci_v3_init); | ||
1016 | |||
1017 | /* | ||
1018 | * Static mappings for the PCIv3 bridge | ||
1019 | * | ||
1020 | * e8000000 40000000 PCI memory PHYS_PCI_MEM_BASE (max 512M) | ||
1021 | * ec000000 61000000 PCI config space PHYS_PCI_CONFIG_BASE (max 16M) | ||
1022 | * fee00000 60000000 PCI IO PHYS_PCI_IO_BASE (max 16M) | ||
1023 | */ | ||
1024 | static struct map_desc pci_v3_io_desc[] __initdata __maybe_unused = { | ||
1025 | { | ||
1026 | .virtual = (unsigned long)PCI_MEMORY_VADDR, | ||
1027 | .pfn = __phys_to_pfn(PHYS_PCI_MEM_BASE), | ||
1028 | .length = SZ_16M, | ||
1029 | .type = MT_DEVICE | ||
1030 | }, { | ||
1031 | .virtual = (unsigned long)PCI_CONFIG_VADDR, | ||
1032 | .pfn = __phys_to_pfn(PHYS_PCI_CONFIG_BASE), | ||
1033 | .length = SZ_16M, | ||
1034 | .type = MT_DEVICE | ||
1035 | } | ||
1036 | }; | ||
1037 | |||
1038 | int __init pci_v3_early_init(void) | ||
1039 | { | ||
1040 | iotable_init(pci_v3_io_desc, ARRAY_SIZE(pci_v3_io_desc)); | ||
1041 | vga_base = (unsigned long)PCI_MEMORY_VADDR; | ||
1042 | pci_map_io_early(__phys_to_pfn(PHYS_PCI_IO_BASE)); | ||
1043 | return 0; | ||
612 | } | 1044 | } |