2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (C) 2000, 2001 Keith M Wesolowski
8 #include <linux/kernel.h>
9 #include <linux/init.h>
10 #include <linux/pci.h>
11 #include <linux/types.h>
13 #include <asm/ip32/mace.h>
14 #include <asm/ip32/crime.h>
15 #include <asm/ip32/ip32_ints.h>
16 #include <linux/delay.h>
21 * O2 has up to 5 PCI devices connected into the MACE bridge. The device
22 * map looks like this:
31 #define chkslot(_bus,_devfn) \
33 if ((_bus)->number > 0 || PCI_SLOT (_devfn) < 1 \
34 || PCI_SLOT (_devfn) > 3) \
35 return PCIBIOS_DEVICE_NOT_FOUND; \
38 #define mkaddr(_devfn, where) \
39 ((((_devfn) & 0xffUL) << 8) | ((where) & 0xfcUL))
41 void macepci_error(int irq
, void *dev
, struct pt_regs
*regs
);
43 static int macepci_read_config(struct pci_bus
*bus
, unsigned int devfn
,
44 int where
, int size
, u32
* val
)
50 mace_write_32(MACEPCI_CONFIG_ADDR
, mkaddr(devfn
, where
));
52 mace_read_8(MACEPCI_CONFIG_DATA
+
53 ((where
& 3UL) ^ 3UL));
55 return PCIBIOS_SUCCESSFUL
;
61 return PCIBIOS_BAD_REGISTER_NUMBER
;
62 mace_write_32(MACEPCI_CONFIG_ADDR
, mkaddr(devfn
, where
));
64 mace_read_16(MACEPCI_CONFIG_DATA
+
65 ((where
& 2UL) ^ 2UL));
67 return PCIBIOS_SUCCESSFUL
;
73 return PCIBIOS_BAD_REGISTER_NUMBER
;
74 mace_write_32(MACEPCI_CONFIG_ADDR
, mkaddr(devfn
, where
));
75 *val
= mace_read_32(MACEPCI_CONFIG_DATA
);
77 return PCIBIOS_SUCCESSFUL
;
81 static int macepci_write_config(struct pci_bus
*bus
, unsigned int devfn
,
82 int where
, int size
, u32 val
)
87 mace_write_32(MACEPCI_CONFIG_ADDR
, mkaddr(devfn
, where
));
88 mace_write_8(MACEPCI_CONFIG_DATA
+ ((where
& 3UL) ^ 3UL),
91 return PCIBIOS_SUCCESSFUL
;
96 return PCIBIOS_BAD_REGISTER_NUMBER
;
97 mace_write_32(MACEPCI_CONFIG_ADDR
, mkaddr(devfn
, where
));
98 mace_write_16(MACEPCI_CONFIG_DATA
+ ((where
& 2UL) ^ 2UL),
101 return PCIBIOS_SUCCESSFUL
;
106 return PCIBIOS_BAD_REGISTER_NUMBER
;
107 mace_write_32(MACEPCI_CONFIG_ADDR
, mkaddr(devfn
, where
));
108 mace_write_32(MACEPCI_CONFIG_DATA
, val
);
110 return PCIBIOS_SUCCESSFUL
;
114 static struct pci_ops macepci_ops
= {
115 .read
= macepci_read_config
,
116 .write
= macepci_write_config
,
119 struct pci_fixup pcibios_fixups
[] = { {0} };
121 static int __init
pcibios_init(void)
126 u32 base_io
= 0x3000; /* The first i/o address to assign after SCSI */
127 u32 base_mem
= 0x80100000; /* Likewise */
128 u32 rev
= mace_read_32(MACEPCI_REV
);
131 printk("MACE: PCI rev %d detected at %016lx\n", rev
,
132 (u64
) MACE_BASE
+ MACE_PCI
);
134 /* These are *bus* addresses */
135 ioport_resource
.start
= 0;
136 ioport_resource
.end
= 0xffffffffUL
;
137 iomem_resource
.start
= 0x80000000UL
;
138 iomem_resource
.end
= 0xffffffffUL
;
140 /* Clear any outstanding errors and enable interrupts */
141 mace_write_32(MACEPCI_ERROR_ADDR
, 0);
142 mace_write_32(MACEPCI_ERROR_FLAGS
, 0);
143 mace_write_32(MACEPCI_CONTROL
, 0xff008500);
144 crime_write_64(CRIME_HARD_INT
, 0UL);
145 crime_write_64(CRIME_SOFT_INT
, 0UL);
146 crime_write_64(CRIME_INT_STAT
, 0x000000000000ff00UL
);
148 if (request_irq(MACE_PCI_BRIDGE_IRQ
, macepci_error
, 0,
149 "MACE PCI error", NULL
))
150 panic("PCI bridge can't get interrupt; can't happen.");
152 pci_scan_bus(0, &macepci_ops
, NULL
);
154 #ifdef DEBUG_MACE_PCI
155 pci_for_each_dev(dev
) {
156 printk("Device: %d/%d/%d ARCS-assigned bus resource map\n",
157 dev
->bus
->number
, PCI_SLOT(dev
->devfn
),
158 PCI_FUNC(dev
->devfn
));
159 for (i
= 0; i
< DEVICE_COUNT_RESOURCE
; i
++) {
160 if (dev
->resource
[i
].start
== 0)
162 printk("%d: %016lx - %016lx (flags %04lx)\n",
163 i
, dev
->resource
[i
].start
,
164 dev
->resource
[i
].end
,
165 dev
->resource
[i
].flags
);
170 * Assign sane resources to and enable all devices. The requirement
171 * for the SCSI controllers is well-known: a 256-byte I/O region
172 * which we must assign, and a 1-page memory region which is
173 * assigned by the system firmware.
175 pci_for_each_dev(dev
) {
176 switch (PCI_SLOT(dev
->devfn
)) {
177 case 1: /* SCSI bus 0 */
178 dev
->resource
[0].start
= 0x1000UL
;
179 dev
->resource
[0].end
= 0x10ffUL
;
181 case 2: /* SCSI bus 1 */
182 dev
->resource
[0].start
= 0x2000UL
;
183 dev
->resource
[0].end
= 0x20ffUL
;
185 default: /* Slots - I guess we have only 1 */
186 for (i
= 0; i
< 6; i
++) {
187 size
= dev
->resource
[i
].end
188 - dev
->resource
[i
].start
;
190 || !(dev
->resource
[i
].flags
193 dev
->resource
[i
].start
=
194 dev
->resource
[i
].end
= 0UL;
197 if (dev
->resource
[i
].flags
& IORESOURCE_IO
) {
198 dev
->resource
[i
].start
= base_io
;
199 base_io
+= PAGE_ALIGN(size
);
201 dev
->resource
[i
].start
= base_mem
;
202 base_mem
+= 0x100000UL
;
204 dev
->resource
[i
].end
=
205 dev
->resource
[i
].start
+ size
;
209 for (i
= 0; i
< 6; i
++) {
210 if (dev
->resource
[i
].start
== 0)
212 start
= dev
->resource
[i
].start
;
213 if (dev
->resource
[i
].flags
& IORESOURCE_IO
)
215 pci_write_config_dword(dev
,
217 (i
<< 2), (u32
) start
);
219 pci_write_config_byte(dev
, PCI_CACHE_LINE_SIZE
, 0x20);
220 pci_write_config_byte(dev
, PCI_LATENCY_TIMER
, 0x30);
221 pci_read_config_word(dev
, PCI_COMMAND
, &cmd
);
223 (PCI_COMMAND_IO
| PCI_COMMAND_MEMORY
|
224 PCI_COMMAND_SPECIAL
| PCI_COMMAND_INVALIDATE
|
226 pci_write_config_word(dev
, PCI_COMMAND
, cmd
);
230 * Fixup O2 PCI slot. Bad hack.
232 /* devtag = pci_make_tag(0, 0, 3, 0);
234 slot = macepci_conf_read(0, devtag, PCI_COMMAND_STATUS_REG);
235 slot |= PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE;
236 macepci_conf_write(0, devtag, PCI_COMMAND_STATUS_REG, slot);
238 slot = macepci_conf_read(0, devtag, PCI_MAPREG_START);
239 if (slot == 0xffffffe1)
240 macepci_conf_write(0, devtag, PCI_MAPREG_START, 0x00001000);
242 slot = macepci_conf_read(0, devtag, PCI_MAPREG_START + (2 << 2));
243 if ((slot & 0xffff0000) == 0) {
245 macepci_conf_write(0, devtag, PCI_MAPREG_START + (2 << 2),
249 #ifdef DEBUG_MACE_PCI
250 printk("Triggering PCI bridge interrupt...\n");
251 mace_write_32(MACEPCI_ERROR_FLAGS
, MACEPCI_ERROR_INTERRUPT_TEST
);
253 pci_for_each_dev(dev
) {
254 printk("Device: %d/%d/%d final bus resource map\n",
255 dev
->bus
->number
, PCI_SLOT(dev
->devfn
),
256 PCI_FUNC(dev
->devfn
));
257 for (i
= 0; i
< DEVICE_COUNT_RESOURCE
; i
++) {
258 if (dev
->resource
[i
].start
== 0)
260 printk("%d: %016lx - %016lx (flags %04lx)\n",
261 i
, dev
->resource
[i
].start
,
262 dev
->resource
[i
].end
,
263 dev
->resource
[i
].flags
);
271 subsys_initcall(pcibios_init
);
274 * Given a PCI slot number (a la PCI_SLOT(...)) and the interrupt pin of
275 * the device (1-4 => A-D), tell what irq to use. Note that we don't
276 * in theory have slots 4 and 5, and we never normally use the shared
277 * irqs. I suppose a device without a pin A will thank us for doing it
278 * right if there exists such a broken piece of crap.
280 static int __devinit
macepci_map_irq(struct pci_dev
*dev
, u8 slot
, u8 pin
)
282 chkslot(dev
->bus
, dev
->devfn
);
287 return MACEPCI_SCSI0_IRQ
;
289 return MACEPCI_SCSI1_IRQ
;
293 return MACEPCI_SHARED0_IRQ
;
295 return MACEPCI_SHARED1_IRQ
;
297 return MACEPCI_SHARED2_IRQ
;
300 return MACEPCI_SLOT0_IRQ
;
305 return MACEPCI_SHARED2_IRQ
;
307 return MACEPCI_SHARED0_IRQ
;
309 return MACEPCI_SHARED1_IRQ
;
312 return MACEPCI_SLOT1_IRQ
;
314 return MACEPCI_SLOT1_IRQ
;
318 return MACEPCI_SHARED1_IRQ
;
320 return MACEPCI_SHARED2_IRQ
;
322 return MACEPCI_SHARED0_IRQ
;
325 return MACEPCI_SLOT2_IRQ
;
333 * It's not entirely clear what this does in a system with no bridges.
334 * In any case, bridges are not supported by Linux in O2.
336 static u8 __init
macepci_swizzle(struct pci_dev
*dev
, u8
* pinp
)
338 if (PCI_SLOT(dev
->devfn
) == 2)
342 return PCI_SLOT(dev
->devfn
);
345 /* All devices are enabled during initialization. */
346 int pcibios_enable_device(struct pci_dev
*dev
, int mask
)
348 return PCIBIOS_SUCCESSFUL
;
351 char *__init
pcibios_setup(char *str
)
356 void pcibios_align_resource(void *data
, struct resource
*res
,
357 unsigned long size
, unsigned long align
)
361 void __init
pcibios_update_irq(struct pci_dev
*dev
, int irq
)
363 pci_write_config_byte(dev
, PCI_INTERRUPT_LINE
, irq
);
366 void __devinit
pcibios_fixup_bus(struct pci_bus
*b
)
368 pci_fixup_irqs(macepci_swizzle
, macepci_map_irq
);
372 * Handle errors from the bridge. This includes master and target aborts,
373 * various command and address errors, and the interrupt test. This gets
374 * registered on the bridge error irq. It's conceivable that some of these
375 * conditions warrant a panic. Anybody care to say which ones?
377 void macepci_error(int irq
, void *dev
, struct pt_regs
*regs
)
379 u32 flags
, error_addr
;
382 flags
= mace_read_32(MACEPCI_ERROR_FLAGS
);
383 error_addr
= mace_read_32(MACEPCI_ERROR_ADDR
);
385 if (flags
& MACEPCI_ERROR_MEMORY_ADDR
)
387 else if (flags
& MACEPCI_ERROR_CONFIG_ADDR
)
392 if (flags
& MACEPCI_ERROR_MASTER_ABORT
) {
393 printk("MACEPCI: Master abort at 0x%08x (%c)\n",
395 mace_write_32(MACEPCI_ERROR_FLAGS
,
396 flags
& ~MACEPCI_ERROR_MASTER_ABORT
);
398 if (flags
& MACEPCI_ERROR_TARGET_ABORT
) {
399 printk("MACEPCI: Target abort at 0x%08x (%c)\n",
401 mace_write_32(MACEPCI_ERROR_FLAGS
,
402 flags
& ~MACEPCI_ERROR_TARGET_ABORT
);
404 if (flags
& MACEPCI_ERROR_DATA_PARITY_ERR
) {
405 printk("MACEPCI: Data parity error at 0x%08x (%c)\n",
407 mace_write_32(MACEPCI_ERROR_FLAGS
, flags
408 & ~MACEPCI_ERROR_DATA_PARITY_ERR
);
410 if (flags
& MACEPCI_ERROR_RETRY_ERR
) {
411 printk("MACEPCI: Retry error at 0x%08x (%c)\n", error_addr
,
413 mace_write_32(MACEPCI_ERROR_FLAGS
, flags
414 & ~MACEPCI_ERROR_RETRY_ERR
);
416 if (flags
& MACEPCI_ERROR_ILLEGAL_CMD
) {
417 printk("MACEPCI: Illegal command at 0x%08x (%c)\n",
419 mace_write_32(MACEPCI_ERROR_FLAGS
,
420 flags
& ~MACEPCI_ERROR_ILLEGAL_CMD
);
422 if (flags
& MACEPCI_ERROR_SYSTEM_ERR
) {
423 printk("MACEPCI: System error at 0x%08x (%c)\n",
425 mace_write_32(MACEPCI_ERROR_FLAGS
, flags
426 & ~MACEPCI_ERROR_SYSTEM_ERR
);
428 if (flags
& MACEPCI_ERROR_PARITY_ERR
) {
429 printk("MACEPCI: Parity error at 0x%08x (%c)\n",
431 mace_write_32(MACEPCI_ERROR_FLAGS
,
432 flags
& ~MACEPCI_ERROR_PARITY_ERR
);
434 if (flags
& MACEPCI_ERROR_OVERRUN
) {
435 printk("MACEPCI: Overrun error at 0x%08x (%c)\n",
437 mace_write_32(MACEPCI_ERROR_FLAGS
, flags
438 & ~MACEPCI_ERROR_OVERRUN
);
440 if (flags
& MACEPCI_ERROR_SIG_TABORT
) {
441 printk("MACEPCI: Signaled target abort (clearing)\n");
442 mace_write_32(MACEPCI_ERROR_FLAGS
, flags
443 & ~MACEPCI_ERROR_SIG_TABORT
);
445 if (flags
& MACEPCI_ERROR_INTERRUPT_TEST
) {
446 printk("MACEPCI: Interrupt test triggered (clearing)\n");
447 mace_write_32(MACEPCI_ERROR_FLAGS
, flags
448 & ~MACEPCI_ERROR_INTERRUPT_TEST
);
452 unsigned int pcibios_assign_all_busses(void)