1 /* $Id: pci_psycho.c,v 1.33 2002/02/01 00:58:33 davem Exp $
2 * pci_psycho.c: PSYCHO/U2P specific PCI controller support.
4 * Copyright (C) 1997, 1998, 1999 David S. Miller (davem@caipfs.rutgers.edu)
5 * Copyright (C) 1998, 1999 Eddie C. Dost (ecd@skynet.be)
6 * Copyright (C) 1999 Jakub Jelinek (jakub@redhat.com)
9 #include <linux/kernel.h>
10 #include <linux/types.h>
11 #include <linux/pci.h>
12 #include <linux/init.h>
13 #include <linux/slab.h>
14 #include <linux/interrupt.h>
17 #include <asm/iommu.h>
19 #include <asm/starfire.h>
22 #include "iommu_common.h"
24 /* All PSYCHO registers are 64-bits. The following accessor
25 * routines are how they are accessed. The REG parameter
26 * is a physical address.
28 #define psycho_read(__reg) \
30 __asm__ __volatile__("ldxa [%1] %2, %0" \
32 : "r" (__reg), "i" (ASI_PHYS_BYPASS_EC_E) \
36 #define psycho_write(__reg, __val) \
37 __asm__ __volatile__("stxa %0, [%1] %2" \
39 : "r" (__val), "r" (__reg), \
40 "i" (ASI_PHYS_BYPASS_EC_E) \
43 /* Misc. PSYCHO PCI controller register offsets and definitions. */
44 #define PSYCHO_CONTROL 0x0010UL
45 #define PSYCHO_CONTROL_IMPL 0xf000000000000000UL /* Implementation of this PSYCHO*/
46 #define PSYCHO_CONTROL_VER 0x0f00000000000000UL /* Version of this PSYCHO */
47 #define PSYCHO_CONTROL_MID 0x00f8000000000000UL /* UPA Module ID of PSYCHO */
48 #define PSYCHO_CONTROL_IGN 0x0007c00000000000UL /* Interrupt Group Number */
49 #define PSYCHO_CONTROL_RESV 0x00003ffffffffff0UL /* Reserved */
50 #define PSYCHO_CONTROL_APCKEN 0x0000000000000008UL /* Address Parity Check Enable */
51 #define PSYCHO_CONTROL_APERR 0x0000000000000004UL /* Incoming System Addr Parerr */
52 #define PSYCHO_CONTROL_IAP 0x0000000000000002UL /* Invert UPA Parity */
53 #define PSYCHO_CONTROL_MODE 0x0000000000000001UL /* PSYCHO clock mode */
54 #define PSYCHO_PCIA_CTRL 0x2000UL
55 #define PSYCHO_PCIB_CTRL 0x4000UL
56 #define PSYCHO_PCICTRL_RESV1 0xfffffff000000000UL /* Reserved */
57 #define PSYCHO_PCICTRL_SBH_ERR 0x0000000800000000UL /* Streaming byte hole error */
58 #define PSYCHO_PCICTRL_SERR 0x0000000400000000UL /* SERR signal asserted */
59 #define PSYCHO_PCICTRL_SPEED 0x0000000200000000UL /* PCI speed (1 is U2P clock) */
60 #define PSYCHO_PCICTRL_RESV2 0x00000001ffc00000UL /* Reserved */
61 #define PSYCHO_PCICTRL_ARB_PARK 0x0000000000200000UL /* PCI arbitration parking */
62 #define PSYCHO_PCICTRL_RESV3 0x00000000001ff800UL /* Reserved */
63 #define PSYCHO_PCICTRL_SBH_INT 0x0000000000000400UL /* Streaming byte hole int enab */
64 #define PSYCHO_PCICTRL_WEN 0x0000000000000200UL /* Power Mgmt Wake Enable */
65 #define PSYCHO_PCICTRL_EEN 0x0000000000000100UL /* PCI Error Interrupt Enable */
66 #define PSYCHO_PCICTRL_RESV4 0x00000000000000c0UL /* Reserved */
67 #define PSYCHO_PCICTRL_AEN 0x000000000000003fUL /* PCI DVMA Arbitration Enable */
69 /* U2P Programmer's Manual, page 13-55, configuration space
72 * 32 24 23 16 15 11 10 8 7 2 1 0
73 * ---------------------------------------------------------
74 * |0 0 0 0 0 0 0 0 1| bus | device | function | reg | 0 0 |
75 * ---------------------------------------------------------
77 #define PSYCHO_CONFIG_BASE(PBM) \
78 ((PBM)->config_space | (1UL << 24))
79 #define PSYCHO_CONFIG_ENCODE(BUS, DEVFN, REG) \
80 (((unsigned long)(BUS) << 16) | \
81 ((unsigned long)(DEVFN) << 8) | \
82 ((unsigned long)(REG)))
84 static void *psycho_pci_config_mkaddr(struct pci_pbm_info *pbm,
92 (PSYCHO_CONFIG_BASE(pbm) |
93 PSYCHO_CONFIG_ENCODE(bus, devfn, where));
96 static int psycho_out_of_range(struct pci_pbm_info *pbm,
100 return ((pbm->parent == 0) ||
101 ((pbm == &pbm->parent->pbm_B) &&
102 (bus == pbm->pci_first_busno) &&
103 PCI_SLOT(devfn) > 8) ||
104 ((pbm == &pbm->parent->pbm_A) &&
105 (bus == pbm->pci_first_busno) &&
106 PCI_SLOT(devfn) > 8));
109 /* PSYCHO PCI configuration space accessors. */
111 static int psycho_read_pci_cfg(struct pci_bus *bus_dev, unsigned int devfn,
112 int where, int size, u32 *value)
114 struct pci_pbm_info *pbm = bus_dev->sysdata;
115 unsigned char bus = bus_dev->number;
132 addr = psycho_pci_config_mkaddr(pbm, bus, devfn, where);
134 return PCIBIOS_SUCCESSFUL;
136 if (psycho_out_of_range(pbm, bus, devfn))
137 return PCIBIOS_SUCCESSFUL;
140 pci_config_read8((u8 *)addr, &tmp8);
146 printk("pci_read_config_word: misaligned reg [%x]\n",
148 return PCIBIOS_SUCCESSFUL;
150 pci_config_read16((u16 *)addr, &tmp16);
151 *value = (u32) tmp16;
156 printk("pci_read_config_dword: misaligned reg [%x]\n",
158 return PCIBIOS_SUCCESSFUL;
160 pci_config_read32(addr, value);
163 return PCIBIOS_SUCCESSFUL;
166 static int psycho_write_pci_cfg(struct pci_bus *bus_dev, unsigned int devfn,
167 int where, int size, u32 value)
169 struct pci_pbm_info *pbm = bus_dev->sysdata;
170 unsigned char bus = bus_dev->number;
173 addr = psycho_pci_config_mkaddr(pbm, bus, devfn, where);
175 return PCIBIOS_SUCCESSFUL;
177 if (psycho_out_of_range(pbm, bus, devfn))
178 return PCIBIOS_SUCCESSFUL;
182 pci_config_write8((u8 *)addr, value);
187 printk("pci_write_config_word: misaligned reg [%x]\n",
189 return PCIBIOS_SUCCESSFUL;
191 pci_config_write16((u16 *)addr, value);
196 printk("pci_write_config_dword: misaligned reg [%x]\n",
198 return PCIBIOS_SUCCESSFUL;
200 pci_config_write32(addr, value);
202 return PCIBIOS_SUCCESSFUL;
205 static struct pci_ops psycho_ops = {
206 .read = psycho_read_pci_cfg,
207 .write = psycho_write_pci_cfg,
210 /* PSYCHO interrupt mapping support. */
211 #define PSYCHO_IMAP_A_SLOT0 0x0c00UL
212 #define PSYCHO_IMAP_B_SLOT0 0x0c20UL
213 static unsigned long psycho_pcislot_imap_offset(unsigned long ino)
215 unsigned int bus = (ino & 0x10) >> 4;
216 unsigned int slot = (ino & 0x0c) >> 2;
219 return PSYCHO_IMAP_A_SLOT0 + (slot * 8);
221 return PSYCHO_IMAP_B_SLOT0 + (slot * 8);
224 #define PSYCHO_IMAP_SCSI 0x1000UL
225 #define PSYCHO_IMAP_ETH 0x1008UL
226 #define PSYCHO_IMAP_BPP 0x1010UL
227 #define PSYCHO_IMAP_AU_REC 0x1018UL
228 #define PSYCHO_IMAP_AU_PLAY 0x1020UL
229 #define PSYCHO_IMAP_PFAIL 0x1028UL
230 #define PSYCHO_IMAP_KMS 0x1030UL
231 #define PSYCHO_IMAP_FLPY 0x1038UL
232 #define PSYCHO_IMAP_SHW 0x1040UL
233 #define PSYCHO_IMAP_KBD 0x1048UL
234 #define PSYCHO_IMAP_MS 0x1050UL
235 #define PSYCHO_IMAP_SER 0x1058UL
236 #define PSYCHO_IMAP_TIM0 0x1060UL
237 #define PSYCHO_IMAP_TIM1 0x1068UL
238 #define PSYCHO_IMAP_UE 0x1070UL
239 #define PSYCHO_IMAP_CE 0x1078UL
240 #define PSYCHO_IMAP_A_ERR 0x1080UL
241 #define PSYCHO_IMAP_B_ERR 0x1088UL
242 #define PSYCHO_IMAP_PMGMT 0x1090UL
243 #define PSYCHO_IMAP_GFX 0x1098UL
244 #define PSYCHO_IMAP_EUPA 0x10a0UL
246 static unsigned long __onboard_imap_off[] = {
247 /*0x20*/ PSYCHO_IMAP_SCSI,
248 /*0x21*/ PSYCHO_IMAP_ETH,
249 /*0x22*/ PSYCHO_IMAP_BPP,
250 /*0x23*/ PSYCHO_IMAP_AU_REC,
251 /*0x24*/ PSYCHO_IMAP_AU_PLAY,
252 /*0x25*/ PSYCHO_IMAP_PFAIL,
253 /*0x26*/ PSYCHO_IMAP_KMS,
254 /*0x27*/ PSYCHO_IMAP_FLPY,
255 /*0x28*/ PSYCHO_IMAP_SHW,
256 /*0x29*/ PSYCHO_IMAP_KBD,
257 /*0x2a*/ PSYCHO_IMAP_MS,
258 /*0x2b*/ PSYCHO_IMAP_SER,
259 /*0x2c*/ PSYCHO_IMAP_TIM0,
260 /*0x2d*/ PSYCHO_IMAP_TIM1,
261 /*0x2e*/ PSYCHO_IMAP_UE,
262 /*0x2f*/ PSYCHO_IMAP_CE,
263 /*0x30*/ PSYCHO_IMAP_A_ERR,
264 /*0x31*/ PSYCHO_IMAP_B_ERR,
265 /*0x32*/ PSYCHO_IMAP_PMGMT
267 #define PSYCHO_ONBOARD_IRQ_BASE 0x20
268 #define PSYCHO_ONBOARD_IRQ_LAST 0x32
269 #define psycho_onboard_imap_offset(__ino) \
270 __onboard_imap_off[(__ino) - PSYCHO_ONBOARD_IRQ_BASE]
272 #define PSYCHO_ICLR_A_SLOT0 0x1400UL
273 #define PSYCHO_ICLR_SCSI 0x1800UL
275 #define psycho_iclr_offset(ino) \
276 ((ino & 0x20) ? (PSYCHO_ICLR_SCSI + (((ino) & 0x1f) << 3)) : \
277 (PSYCHO_ICLR_A_SLOT0 + (((ino) & 0x1f)<<3)))
279 static unsigned int psycho_irq_build(struct pci_pbm_info *pbm,
280 struct pci_dev *pdev,
283 struct ino_bucket *bucket;
284 unsigned long imap, iclr;
285 unsigned long imap_off, iclr_off;
289 if (ino < PSYCHO_ONBOARD_IRQ_BASE) {
291 imap_off = psycho_pcislot_imap_offset(ino);
294 if (ino > PSYCHO_ONBOARD_IRQ_LAST) {
295 prom_printf("psycho_irq_build: Wacky INO [%x]\n", ino);
298 imap_off = psycho_onboard_imap_offset(ino);
301 /* Now build the IRQ bucket. */
302 imap = pbm->controller_regs + imap_off;
305 iclr_off = psycho_iclr_offset(ino);
306 iclr = pbm->controller_regs + iclr_off;
309 if ((ino & 0x20) == 0)
310 inofixup = ino & 0x03;
312 bucket = __bucket(build_irq(inofixup, iclr, imap));
313 bucket->flags |= IBF_PCI;
315 return __irq(bucket);
318 /* PSYCHO error handling support. */
319 enum psycho_error_type {
320 UE_ERR, CE_ERR, PCI_ERR
323 /* Helper function of IOMMU error checking, which checks out
324 * the state of the streaming buffers. The IOMMU lock is
325 * held when this is called.
327 * For the PCI error case we know which PBM (and thus which
328 * streaming buffer) caused the error, but for the uncorrectable
329 * error case we do not. So we always check both streaming caches.
331 #define PSYCHO_STRBUF_CONTROL_A 0x2800UL
332 #define PSYCHO_STRBUF_CONTROL_B 0x4800UL
333 #define PSYCHO_STRBUF_CTRL_LPTR 0x00000000000000f0UL /* LRU Lock Pointer */
334 #define PSYCHO_STRBUF_CTRL_LENAB 0x0000000000000008UL /* LRU Lock Enable */
335 #define PSYCHO_STRBUF_CTRL_RRDIS 0x0000000000000004UL /* Rerun Disable */
336 #define PSYCHO_STRBUF_CTRL_DENAB 0x0000000000000002UL /* Diagnostic Mode Enable */
337 #define PSYCHO_STRBUF_CTRL_ENAB 0x0000000000000001UL /* Streaming Buffer Enable */
338 #define PSYCHO_STRBUF_FLUSH_A 0x2808UL
339 #define PSYCHO_STRBUF_FLUSH_B 0x4808UL
340 #define PSYCHO_STRBUF_FSYNC_A 0x2810UL
341 #define PSYCHO_STRBUF_FSYNC_B 0x4810UL
342 #define PSYCHO_STC_DATA_A 0xb000UL
343 #define PSYCHO_STC_DATA_B 0xc000UL
344 #define PSYCHO_STC_ERR_A 0xb400UL
345 #define PSYCHO_STC_ERR_B 0xc400UL
346 #define PSYCHO_STCERR_WRITE 0x0000000000000002UL /* Write Error */
347 #define PSYCHO_STCERR_READ 0x0000000000000001UL /* Read Error */
348 #define PSYCHO_STC_TAG_A 0xb800UL
349 #define PSYCHO_STC_TAG_B 0xc800UL
350 #define PSYCHO_STCTAG_PPN 0x0fffffff00000000UL /* Physical Page Number */
351 #define PSYCHO_STCTAG_VPN 0x00000000ffffe000UL /* Virtual Page Number */
352 #define PSYCHO_STCTAG_VALID 0x0000000000000002UL /* Valid */
353 #define PSYCHO_STCTAG_WRITE 0x0000000000000001UL /* Writable */
354 #define PSYCHO_STC_LINE_A 0xb900UL
355 #define PSYCHO_STC_LINE_B 0xc900UL
356 #define PSYCHO_STCLINE_LINDX 0x0000000001e00000UL /* LRU Index */
357 #define PSYCHO_STCLINE_SPTR 0x00000000001f8000UL /* Dirty Data Start Pointer */
358 #define PSYCHO_STCLINE_LADDR 0x0000000000007f00UL /* Line Address */
359 #define PSYCHO_STCLINE_EPTR 0x00000000000000fcUL /* Dirty Data End Pointer */
360 #define PSYCHO_STCLINE_VALID 0x0000000000000002UL /* Valid */
361 #define PSYCHO_STCLINE_FOFN 0x0000000000000001UL /* Fetch Outstanding / Flush Necessary */
363 static DEFINE_SPINLOCK(stc_buf_lock);
364 static unsigned long stc_error_buf[128];
365 static unsigned long stc_tag_buf[16];
366 static unsigned long stc_line_buf[16];
368 static void __psycho_check_one_stc(struct pci_controller_info *p,
369 struct pci_pbm_info *pbm,
372 struct pci_strbuf *strbuf = &pbm->stc;
373 unsigned long regbase = p->pbm_A.controller_regs;
374 unsigned long err_base, tag_base, line_base;
379 err_base = regbase + PSYCHO_STC_ERR_A;
380 tag_base = regbase + PSYCHO_STC_TAG_A;
381 line_base = regbase + PSYCHO_STC_LINE_A;
383 err_base = regbase + PSYCHO_STC_ERR_B;
384 tag_base = regbase + PSYCHO_STC_TAG_B;
385 line_base = regbase + PSYCHO_STC_LINE_B;
388 spin_lock(&stc_buf_lock);
390 /* This is __REALLY__ dangerous. When we put the
391 * streaming buffer into diagnostic mode to probe
392 * it's tags and error status, we _must_ clear all
393 * of the line tag valid bits before re-enabling
394 * the streaming buffer. If any dirty data lives
395 * in the STC when we do this, we will end up
396 * invalidating it before it has a chance to reach
399 control = psycho_read(strbuf->strbuf_control);
400 psycho_write(strbuf->strbuf_control,
401 (control | PSYCHO_STRBUF_CTRL_DENAB));
402 for (i = 0; i < 128; i++) {
405 val = psycho_read(err_base + (i * 8UL));
406 psycho_write(err_base + (i * 8UL), 0UL);
407 stc_error_buf[i] = val;
409 for (i = 0; i < 16; i++) {
410 stc_tag_buf[i] = psycho_read(tag_base + (i * 8UL));
411 stc_line_buf[i] = psycho_read(line_base + (i * 8UL));
412 psycho_write(tag_base + (i * 8UL), 0UL);
413 psycho_write(line_base + (i * 8UL), 0UL);
416 /* OK, state is logged, exit diagnostic mode. */
417 psycho_write(strbuf->strbuf_control, control);
419 for (i = 0; i < 16; i++) {
420 int j, saw_error, first, last;
425 for (j = first; j < last; j++) {
426 unsigned long errval = stc_error_buf[j];
429 printk("PSYCHO%d(PBM%c): STC_ERR(%d)[wr(%d)rd(%d)]\n",
431 (is_pbm_a ? 'A' : 'B'),
433 (errval & PSYCHO_STCERR_WRITE) ? 1 : 0,
434 (errval & PSYCHO_STCERR_READ) ? 1 : 0);
437 if (saw_error != 0) {
438 unsigned long tagval = stc_tag_buf[i];
439 unsigned long lineval = stc_line_buf[i];
440 printk("PSYCHO%d(PBM%c): STC_TAG(%d)[PA(%016lx)VA(%08lx)V(%d)W(%d)]\n",
442 (is_pbm_a ? 'A' : 'B'),
444 ((tagval & PSYCHO_STCTAG_PPN) >> 19UL),
445 (tagval & PSYCHO_STCTAG_VPN),
446 ((tagval & PSYCHO_STCTAG_VALID) ? 1 : 0),
447 ((tagval & PSYCHO_STCTAG_WRITE) ? 1 : 0));
448 printk("PSYCHO%d(PBM%c): STC_LINE(%d)[LIDX(%lx)SP(%lx)LADDR(%lx)EP(%lx)"
451 (is_pbm_a ? 'A' : 'B'),
453 ((lineval & PSYCHO_STCLINE_LINDX) >> 21UL),
454 ((lineval & PSYCHO_STCLINE_SPTR) >> 15UL),
455 ((lineval & PSYCHO_STCLINE_LADDR) >> 8UL),
456 ((lineval & PSYCHO_STCLINE_EPTR) >> 2UL),
457 ((lineval & PSYCHO_STCLINE_VALID) ? 1 : 0),
458 ((lineval & PSYCHO_STCLINE_FOFN) ? 1 : 0));
462 spin_unlock(&stc_buf_lock);
465 static void __psycho_check_stc_error(struct pci_controller_info *p,
468 enum psycho_error_type type)
470 struct pci_pbm_info *pbm;
473 if (pbm->stc.strbuf_enabled)
474 __psycho_check_one_stc(p, pbm, 1);
477 if (pbm->stc.strbuf_enabled)
478 __psycho_check_one_stc(p, pbm, 0);
481 /* When an Uncorrectable Error or a PCI Error happens, we
482 * interrogate the IOMMU state to see if it is the cause.
484 #define PSYCHO_IOMMU_CONTROL 0x0200UL
485 #define PSYCHO_IOMMU_CTRL_RESV 0xfffffffff9000000UL /* Reserved */
486 #define PSYCHO_IOMMU_CTRL_XLTESTAT 0x0000000006000000UL /* Translation Error Status */
487 #define PSYCHO_IOMMU_CTRL_XLTEERR 0x0000000001000000UL /* Translation Error encountered */
488 #define PSYCHO_IOMMU_CTRL_LCKEN 0x0000000000800000UL /* Enable translation locking */
489 #define PSYCHO_IOMMU_CTRL_LCKPTR 0x0000000000780000UL /* Translation lock pointer */
490 #define PSYCHO_IOMMU_CTRL_TSBSZ 0x0000000000070000UL /* TSB Size */
491 #define PSYCHO_IOMMU_TSBSZ_1K 0x0000000000000000UL /* TSB Table 1024 8-byte entries */
492 #define PSYCHO_IOMMU_TSBSZ_2K 0x0000000000010000UL /* TSB Table 2048 8-byte entries */
493 #define PSYCHO_IOMMU_TSBSZ_4K 0x0000000000020000UL /* TSB Table 4096 8-byte entries */
494 #define PSYCHO_IOMMU_TSBSZ_8K 0x0000000000030000UL /* TSB Table 8192 8-byte entries */
495 #define PSYCHO_IOMMU_TSBSZ_16K 0x0000000000040000UL /* TSB Table 16k 8-byte entries */
496 #define PSYCHO_IOMMU_TSBSZ_32K 0x0000000000050000UL /* TSB Table 32k 8-byte entries */
497 #define PSYCHO_IOMMU_TSBSZ_64K 0x0000000000060000UL /* TSB Table 64k 8-byte entries */
498 #define PSYCHO_IOMMU_TSBSZ_128K 0x0000000000070000UL /* TSB Table 128k 8-byte entries */
499 #define PSYCHO_IOMMU_CTRL_RESV2 0x000000000000fff8UL /* Reserved */
500 #define PSYCHO_IOMMU_CTRL_TBWSZ 0x0000000000000004UL /* Assumed page size, 0=8k 1=64k */
501 #define PSYCHO_IOMMU_CTRL_DENAB 0x0000000000000002UL /* Diagnostic mode enable */
502 #define PSYCHO_IOMMU_CTRL_ENAB 0x0000000000000001UL /* IOMMU Enable */
503 #define PSYCHO_IOMMU_TSBBASE 0x0208UL
504 #define PSYCHO_IOMMU_FLUSH 0x0210UL
505 #define PSYCHO_IOMMU_TAG 0xa580UL
506 #define PSYCHO_IOMMU_TAG_ERRSTS (0x3UL << 23UL)
507 #define PSYCHO_IOMMU_TAG_ERR (0x1UL << 22UL)
508 #define PSYCHO_IOMMU_TAG_WRITE (0x1UL << 21UL)
509 #define PSYCHO_IOMMU_TAG_STREAM (0x1UL << 20UL)
510 #define PSYCHO_IOMMU_TAG_SIZE (0x1UL << 19UL)
511 #define PSYCHO_IOMMU_TAG_VPAGE 0x7ffffUL
512 #define PSYCHO_IOMMU_DATA 0xa600UL
513 #define PSYCHO_IOMMU_DATA_VALID (1UL << 30UL)
514 #define PSYCHO_IOMMU_DATA_CACHE (1UL << 28UL)
515 #define PSYCHO_IOMMU_DATA_PPAGE 0xfffffffUL
516 static void psycho_check_iommu_error(struct pci_controller_info *p,
519 enum psycho_error_type type)
521 struct pci_iommu *iommu = p->pbm_A.iommu;
522 unsigned long iommu_tag[16];
523 unsigned long iommu_data[16];
528 spin_lock_irqsave(&iommu->lock, flags);
529 control = psycho_read(iommu->iommu_control);
530 if (control & PSYCHO_IOMMU_CTRL_XLTEERR) {
533 /* Clear the error encountered bit. */
534 control &= ~PSYCHO_IOMMU_CTRL_XLTEERR;
535 psycho_write(iommu->iommu_control, control);
537 switch((control & PSYCHO_IOMMU_CTRL_XLTESTAT) >> 25UL) {
539 type_string = "Protection Error";
542 type_string = "Invalid Error";
545 type_string = "TimeOut Error";
549 type_string = "ECC Error";
552 printk("PSYCHO%d: IOMMU Error, type[%s]\n",
553 p->index, type_string);
555 /* Put the IOMMU into diagnostic mode and probe
556 * it's TLB for entries with error status.
558 * It is very possible for another DVMA to occur
559 * while we do this probe, and corrupt the system
560 * further. But we are so screwed at this point
561 * that we are likely to crash hard anyways, so
562 * get as much diagnostic information to the
565 psycho_write(iommu->iommu_control,
566 control | PSYCHO_IOMMU_CTRL_DENAB);
567 for (i = 0; i < 16; i++) {
568 unsigned long base = p->pbm_A.controller_regs;
571 psycho_read(base + PSYCHO_IOMMU_TAG + (i * 8UL));
573 psycho_read(base + PSYCHO_IOMMU_DATA + (i * 8UL));
575 /* Now clear out the entry. */
576 psycho_write(base + PSYCHO_IOMMU_TAG + (i * 8UL), 0);
577 psycho_write(base + PSYCHO_IOMMU_DATA + (i * 8UL), 0);
580 /* Leave diagnostic mode. */
581 psycho_write(iommu->iommu_control, control);
583 for (i = 0; i < 16; i++) {
584 unsigned long tag, data;
587 if (!(tag & PSYCHO_IOMMU_TAG_ERR))
590 data = iommu_data[i];
591 switch((tag & PSYCHO_IOMMU_TAG_ERRSTS) >> 23UL) {
593 type_string = "Protection Error";
596 type_string = "Invalid Error";
599 type_string = "TimeOut Error";
603 type_string = "ECC Error";
606 printk("PSYCHO%d: IOMMU TAG(%d)[error(%s) wr(%d) str(%d) sz(%dK) vpg(%08lx)]\n",
607 p->index, i, type_string,
608 ((tag & PSYCHO_IOMMU_TAG_WRITE) ? 1 : 0),
609 ((tag & PSYCHO_IOMMU_TAG_STREAM) ? 1 : 0),
610 ((tag & PSYCHO_IOMMU_TAG_SIZE) ? 64 : 8),
611 (tag & PSYCHO_IOMMU_TAG_VPAGE) << IOMMU_PAGE_SHIFT);
612 printk("PSYCHO%d: IOMMU DATA(%d)[valid(%d) cache(%d) ppg(%016lx)]\n",
614 ((data & PSYCHO_IOMMU_DATA_VALID) ? 1 : 0),
615 ((data & PSYCHO_IOMMU_DATA_CACHE) ? 1 : 0),
616 (data & PSYCHO_IOMMU_DATA_PPAGE) << IOMMU_PAGE_SHIFT);
619 __psycho_check_stc_error(p, afsr, afar, type);
620 spin_unlock_irqrestore(&iommu->lock, flags);
623 /* Uncorrectable Errors. Cause of the error and the address are
624 * recorded in the UE_AFSR and UE_AFAR of PSYCHO. They are errors
625 * relating to UPA interface transactions.
627 #define PSYCHO_UE_AFSR 0x0030UL
628 #define PSYCHO_UEAFSR_PPIO 0x8000000000000000UL /* Primary PIO is cause */
629 #define PSYCHO_UEAFSR_PDRD 0x4000000000000000UL /* Primary DVMA read is cause */
630 #define PSYCHO_UEAFSR_PDWR 0x2000000000000000UL /* Primary DVMA write is cause */
631 #define PSYCHO_UEAFSR_SPIO 0x1000000000000000UL /* Secondary PIO is cause */
632 #define PSYCHO_UEAFSR_SDRD 0x0800000000000000UL /* Secondary DVMA read is cause */
633 #define PSYCHO_UEAFSR_SDWR 0x0400000000000000UL /* Secondary DVMA write is cause*/
634 #define PSYCHO_UEAFSR_RESV1 0x03ff000000000000UL /* Reserved */
635 #define PSYCHO_UEAFSR_BMSK 0x0000ffff00000000UL /* Bytemask of failed transfer */
636 #define PSYCHO_UEAFSR_DOFF 0x00000000e0000000UL /* Doubleword Offset */
637 #define PSYCHO_UEAFSR_MID 0x000000001f000000UL /* UPA MID causing the fault */
638 #define PSYCHO_UEAFSR_BLK 0x0000000000800000UL /* Trans was block operation */
639 #define PSYCHO_UEAFSR_RESV2 0x00000000007fffffUL /* Reserved */
640 #define PSYCHO_UE_AFAR 0x0038UL
642 static irqreturn_t psycho_ue_intr(int irq, void *dev_id, struct pt_regs *regs)
644 struct pci_controller_info *p = dev_id;
645 unsigned long afsr_reg = p->pbm_A.controller_regs + PSYCHO_UE_AFSR;
646 unsigned long afar_reg = p->pbm_A.controller_regs + PSYCHO_UE_AFAR;
647 unsigned long afsr, afar, error_bits;
650 /* Latch uncorrectable error status. */
651 afar = psycho_read(afar_reg);
652 afsr = psycho_read(afsr_reg);
654 /* Clear the primary/secondary error status bits. */
656 (PSYCHO_UEAFSR_PPIO | PSYCHO_UEAFSR_PDRD | PSYCHO_UEAFSR_PDWR |
657 PSYCHO_UEAFSR_SPIO | PSYCHO_UEAFSR_SDRD | PSYCHO_UEAFSR_SDWR);
660 psycho_write(afsr_reg, error_bits);
663 printk("PSYCHO%d: Uncorrectable Error, primary error type[%s]\n",
665 (((error_bits & PSYCHO_UEAFSR_PPIO) ?
667 ((error_bits & PSYCHO_UEAFSR_PDRD) ?
669 ((error_bits & PSYCHO_UEAFSR_PDWR) ?
670 "DMA Write" : "???")))));
671 printk("PSYCHO%d: bytemask[%04lx] dword_offset[%lx] UPA_MID[%02lx] was_block(%d)\n",
673 (afsr & PSYCHO_UEAFSR_BMSK) >> 32UL,
674 (afsr & PSYCHO_UEAFSR_DOFF) >> 29UL,
675 (afsr & PSYCHO_UEAFSR_MID) >> 24UL,
676 ((afsr & PSYCHO_UEAFSR_BLK) ? 1 : 0));
677 printk("PSYCHO%d: UE AFAR [%016lx]\n", p->index, afar);
678 printk("PSYCHO%d: UE Secondary errors [", p->index);
680 if (afsr & PSYCHO_UEAFSR_SPIO) {
684 if (afsr & PSYCHO_UEAFSR_SDRD) {
686 printk("(DMA Read)");
688 if (afsr & PSYCHO_UEAFSR_SDWR) {
690 printk("(DMA Write)");
696 /* Interrogate IOMMU for error status. */
697 psycho_check_iommu_error(p, afsr, afar, UE_ERR);
702 /* Correctable Errors. */
703 #define PSYCHO_CE_AFSR 0x0040UL
704 #define PSYCHO_CEAFSR_PPIO 0x8000000000000000UL /* Primary PIO is cause */
705 #define PSYCHO_CEAFSR_PDRD 0x4000000000000000UL /* Primary DVMA read is cause */
706 #define PSYCHO_CEAFSR_PDWR 0x2000000000000000UL /* Primary DVMA write is cause */
707 #define PSYCHO_CEAFSR_SPIO 0x1000000000000000UL /* Secondary PIO is cause */
708 #define PSYCHO_CEAFSR_SDRD 0x0800000000000000UL /* Secondary DVMA read is cause */
709 #define PSYCHO_CEAFSR_SDWR 0x0400000000000000UL /* Secondary DVMA write is cause*/
710 #define PSYCHO_CEAFSR_RESV1 0x0300000000000000UL /* Reserved */
711 #define PSYCHO_CEAFSR_ESYND 0x00ff000000000000UL /* Syndrome Bits */
712 #define PSYCHO_CEAFSR_BMSK 0x0000ffff00000000UL /* Bytemask of failed transfer */
713 #define PSYCHO_CEAFSR_DOFF 0x00000000e0000000UL /* Double Offset */
714 #define PSYCHO_CEAFSR_MID 0x000000001f000000UL /* UPA MID causing the fault */
715 #define PSYCHO_CEAFSR_BLK 0x0000000000800000UL /* Trans was block operation */
716 #define PSYCHO_CEAFSR_RESV2 0x00000000007fffffUL /* Reserved */
717 #define PSYCHO_CE_AFAR 0x0040UL
719 static irqreturn_t psycho_ce_intr(int irq, void *dev_id, struct pt_regs *regs)
721 struct pci_controller_info *p = dev_id;
722 unsigned long afsr_reg = p->pbm_A.controller_regs + PSYCHO_CE_AFSR;
723 unsigned long afar_reg = p->pbm_A.controller_regs + PSYCHO_CE_AFAR;
724 unsigned long afsr, afar, error_bits;
727 /* Latch error status. */
728 afar = psycho_read(afar_reg);
729 afsr = psycho_read(afsr_reg);
731 /* Clear primary/secondary error status bits. */
733 (PSYCHO_CEAFSR_PPIO | PSYCHO_CEAFSR_PDRD | PSYCHO_CEAFSR_PDWR |
734 PSYCHO_CEAFSR_SPIO | PSYCHO_CEAFSR_SDRD | PSYCHO_CEAFSR_SDWR);
737 psycho_write(afsr_reg, error_bits);
740 printk("PSYCHO%d: Correctable Error, primary error type[%s]\n",
742 (((error_bits & PSYCHO_CEAFSR_PPIO) ?
744 ((error_bits & PSYCHO_CEAFSR_PDRD) ?
746 ((error_bits & PSYCHO_CEAFSR_PDWR) ?
747 "DMA Write" : "???")))));
749 /* XXX Use syndrome and afar to print out module string just like
750 * XXX UDB CE trap handler does... -DaveM
752 printk("PSYCHO%d: syndrome[%02lx] bytemask[%04lx] dword_offset[%lx] "
753 "UPA_MID[%02lx] was_block(%d)\n",
755 (afsr & PSYCHO_CEAFSR_ESYND) >> 48UL,
756 (afsr & PSYCHO_CEAFSR_BMSK) >> 32UL,
757 (afsr & PSYCHO_CEAFSR_DOFF) >> 29UL,
758 (afsr & PSYCHO_CEAFSR_MID) >> 24UL,
759 ((afsr & PSYCHO_CEAFSR_BLK) ? 1 : 0));
760 printk("PSYCHO%d: CE AFAR [%016lx]\n", p->index, afar);
761 printk("PSYCHO%d: CE Secondary errors [", p->index);
763 if (afsr & PSYCHO_CEAFSR_SPIO) {
767 if (afsr & PSYCHO_CEAFSR_SDRD) {
769 printk("(DMA Read)");
771 if (afsr & PSYCHO_CEAFSR_SDWR) {
773 printk("(DMA Write)");
782 /* PCI Errors. They are signalled by the PCI bus module since they
783 * are associated with a specific bus segment.
785 #define PSYCHO_PCI_AFSR_A 0x2010UL
786 #define PSYCHO_PCI_AFSR_B 0x4010UL
787 #define PSYCHO_PCIAFSR_PMA 0x8000000000000000UL /* Primary Master Abort Error */
788 #define PSYCHO_PCIAFSR_PTA 0x4000000000000000UL /* Primary Target Abort Error */
789 #define PSYCHO_PCIAFSR_PRTRY 0x2000000000000000UL /* Primary Excessive Retries */
790 #define PSYCHO_PCIAFSR_PPERR 0x1000000000000000UL /* Primary Parity Error */
791 #define PSYCHO_PCIAFSR_SMA 0x0800000000000000UL /* Secondary Master Abort Error */
792 #define PSYCHO_PCIAFSR_STA 0x0400000000000000UL /* Secondary Target Abort Error */
793 #define PSYCHO_PCIAFSR_SRTRY 0x0200000000000000UL /* Secondary Excessive Retries */
794 #define PSYCHO_PCIAFSR_SPERR 0x0100000000000000UL /* Secondary Parity Error */
795 #define PSYCHO_PCIAFSR_RESV1 0x00ff000000000000UL /* Reserved */
796 #define PSYCHO_PCIAFSR_BMSK 0x0000ffff00000000UL /* Bytemask of failed transfer */
797 #define PSYCHO_PCIAFSR_BLK 0x0000000080000000UL /* Trans was block operation */
798 #define PSYCHO_PCIAFSR_RESV2 0x0000000040000000UL /* Reserved */
799 #define PSYCHO_PCIAFSR_MID 0x000000003e000000UL /* MID causing the error */
800 #define PSYCHO_PCIAFSR_RESV3 0x0000000001ffffffUL /* Reserved */
801 #define PSYCHO_PCI_AFAR_A 0x2018UL
802 #define PSYCHO_PCI_AFAR_B 0x4018UL
804 static irqreturn_t psycho_pcierr_intr_other(struct pci_pbm_info *pbm, int is_pbm_a)
806 unsigned long csr_reg, csr, csr_error_bits;
807 irqreturn_t ret = IRQ_NONE;
811 csr_reg = pbm->controller_regs + PSYCHO_PCIA_CTRL;
813 csr_reg = pbm->controller_regs + PSYCHO_PCIB_CTRL;
815 csr = psycho_read(csr_reg);
817 csr & (PSYCHO_PCICTRL_SBH_ERR | PSYCHO_PCICTRL_SERR);
818 if (csr_error_bits) {
819 /* Clear the errors. */
820 psycho_write(csr_reg, csr);
823 if (csr_error_bits & PSYCHO_PCICTRL_SBH_ERR)
824 printk("%s: PCI streaming byte hole error asserted.\n",
826 if (csr_error_bits & PSYCHO_PCICTRL_SERR)
827 printk("%s: PCI SERR signal asserted.\n", pbm->name);
830 pci_read_config_word(pbm->pci_bus->self, PCI_STATUS, &stat);
831 if (stat & (PCI_STATUS_PARITY |
832 PCI_STATUS_SIG_TARGET_ABORT |
833 PCI_STATUS_REC_TARGET_ABORT |
834 PCI_STATUS_REC_MASTER_ABORT |
835 PCI_STATUS_SIG_SYSTEM_ERROR)) {
836 printk("%s: PCI bus error, PCI_STATUS[%04x]\n",
838 pci_write_config_word(pbm->pci_bus->self, PCI_STATUS, 0xffff);
844 static irqreturn_t psycho_pcierr_intr(int irq, void *dev_id, struct pt_regs *regs)
846 struct pci_pbm_info *pbm = dev_id;
847 struct pci_controller_info *p = pbm->parent;
848 unsigned long afsr_reg, afar_reg;
849 unsigned long afsr, afar, error_bits;
850 int is_pbm_a, reported;
852 is_pbm_a = (pbm == &pbm->parent->pbm_A);
854 afsr_reg = p->pbm_A.controller_regs + PSYCHO_PCI_AFSR_A;
855 afar_reg = p->pbm_A.controller_regs + PSYCHO_PCI_AFAR_A;
857 afsr_reg = p->pbm_A.controller_regs + PSYCHO_PCI_AFSR_B;
858 afar_reg = p->pbm_A.controller_regs + PSYCHO_PCI_AFAR_B;
861 /* Latch error status. */
862 afar = psycho_read(afar_reg);
863 afsr = psycho_read(afsr_reg);
865 /* Clear primary/secondary error status bits. */
867 (PSYCHO_PCIAFSR_PMA | PSYCHO_PCIAFSR_PTA |
868 PSYCHO_PCIAFSR_PRTRY | PSYCHO_PCIAFSR_PPERR |
869 PSYCHO_PCIAFSR_SMA | PSYCHO_PCIAFSR_STA |
870 PSYCHO_PCIAFSR_SRTRY | PSYCHO_PCIAFSR_SPERR);
872 return psycho_pcierr_intr_other(pbm, is_pbm_a);
873 psycho_write(afsr_reg, error_bits);
876 printk("PSYCHO%d(PBM%c): PCI Error, primary error type[%s]\n",
877 p->index, (is_pbm_a ? 'A' : 'B'),
878 (((error_bits & PSYCHO_PCIAFSR_PMA) ?
880 ((error_bits & PSYCHO_PCIAFSR_PTA) ?
882 ((error_bits & PSYCHO_PCIAFSR_PRTRY) ?
883 "Excessive Retries" :
884 ((error_bits & PSYCHO_PCIAFSR_PPERR) ?
885 "Parity Error" : "???"))))));
886 printk("PSYCHO%d(PBM%c): bytemask[%04lx] UPA_MID[%02lx] was_block(%d)\n",
887 p->index, (is_pbm_a ? 'A' : 'B'),
888 (afsr & PSYCHO_PCIAFSR_BMSK) >> 32UL,
889 (afsr & PSYCHO_PCIAFSR_MID) >> 25UL,
890 (afsr & PSYCHO_PCIAFSR_BLK) ? 1 : 0);
891 printk("PSYCHO%d(PBM%c): PCI AFAR [%016lx]\n",
892 p->index, (is_pbm_a ? 'A' : 'B'), afar);
893 printk("PSYCHO%d(PBM%c): PCI Secondary errors [",
894 p->index, (is_pbm_a ? 'A' : 'B'));
896 if (afsr & PSYCHO_PCIAFSR_SMA) {
898 printk("(Master Abort)");
900 if (afsr & PSYCHO_PCIAFSR_STA) {
902 printk("(Target Abort)");
904 if (afsr & PSYCHO_PCIAFSR_SRTRY) {
906 printk("(Excessive Retries)");
908 if (afsr & PSYCHO_PCIAFSR_SPERR) {
910 printk("(Parity Error)");
916 /* For the error types shown, scan PBM's PCI bus for devices
917 * which have logged that error type.
920 /* If we see a Target Abort, this could be the result of an
921 * IOMMU translation error of some sort. It is extremely
922 * useful to log this information as usually it indicates
923 * a bug in the IOMMU support code or a PCI device driver.
925 if (error_bits & (PSYCHO_PCIAFSR_PTA | PSYCHO_PCIAFSR_STA)) {
926 psycho_check_iommu_error(p, afsr, afar, PCI_ERR);
927 pci_scan_for_target_abort(p, pbm, pbm->pci_bus);
929 if (error_bits & (PSYCHO_PCIAFSR_PMA | PSYCHO_PCIAFSR_SMA))
930 pci_scan_for_master_abort(p, pbm, pbm->pci_bus);
932 /* For excessive retries, PSYCHO/PBM will abort the device
933 * and there is no way to specifically check for excessive
934 * retries in the config space status registers. So what
935 * we hope is that we'll catch it via the master/target
939 if (error_bits & (PSYCHO_PCIAFSR_PPERR | PSYCHO_PCIAFSR_SPERR))
940 pci_scan_for_parity_error(p, pbm, pbm->pci_bus);
945 /* XXX What about PowerFail/PowerManagement??? -DaveM */
946 #define PSYCHO_ECC_CTRL 0x0020
947 #define PSYCHO_ECCCTRL_EE 0x8000000000000000UL /* Enable ECC Checking */
948 #define PSYCHO_ECCCTRL_UE 0x4000000000000000UL /* Enable UE Interrupts */
949 #define PSYCHO_ECCCTRL_CE 0x2000000000000000UL /* Enable CE INterrupts */
950 #define PSYCHO_UE_INO 0x2e
951 #define PSYCHO_CE_INO 0x2f
952 #define PSYCHO_PCIERR_A_INO 0x30
953 #define PSYCHO_PCIERR_B_INO 0x31
954 static void psycho_register_error_handlers(struct pci_controller_info *p)
956 struct pci_pbm_info *pbm = &p->pbm_A; /* arbitrary */
957 unsigned long base = p->pbm_A.controller_regs;
958 unsigned int irq, portid = pbm->portid;
961 /* Build IRQs and register handlers. */
962 irq = psycho_irq_build(pbm, NULL, (portid << 6) | PSYCHO_UE_INO);
963 if (request_irq(irq, psycho_ue_intr,
964 SA_SHIRQ, "PSYCHO UE", p) < 0) {
965 prom_printf("PSYCHO%d: Cannot register UE interrupt.\n",
970 irq = psycho_irq_build(pbm, NULL, (portid << 6) | PSYCHO_CE_INO);
971 if (request_irq(irq, psycho_ce_intr,
972 SA_SHIRQ, "PSYCHO CE", p) < 0) {
973 prom_printf("PSYCHO%d: Cannot register CE interrupt.\n",
979 irq = psycho_irq_build(pbm, NULL, (portid << 6) | PSYCHO_PCIERR_A_INO);
980 if (request_irq(irq, psycho_pcierr_intr,
981 SA_SHIRQ, "PSYCHO PCIERR", &p->pbm_A) < 0) {
982 prom_printf("PSYCHO%d(PBMA): Cannot register PciERR interrupt.\n",
988 irq = psycho_irq_build(pbm, NULL, (portid << 6) | PSYCHO_PCIERR_B_INO);
989 if (request_irq(irq, psycho_pcierr_intr,
990 SA_SHIRQ, "PSYCHO PCIERR", &p->pbm_B) < 0) {
991 prom_printf("PSYCHO%d(PBMB): Cannot register PciERR interrupt.\n",
996 /* Enable UE and CE interrupts for controller. */
997 psycho_write(base + PSYCHO_ECC_CTRL,
1000 PSYCHO_ECCCTRL_CE));
1002 /* Enable PCI Error interrupts and clear error
1003 * bits for each PBM.
1005 tmp = psycho_read(base + PSYCHO_PCIA_CTRL);
1006 tmp |= (PSYCHO_PCICTRL_SERR |
1007 PSYCHO_PCICTRL_SBH_ERR |
1008 PSYCHO_PCICTRL_EEN);
1009 tmp &= ~(PSYCHO_PCICTRL_SBH_INT);
1010 psycho_write(base + PSYCHO_PCIA_CTRL, tmp);
1012 tmp = psycho_read(base + PSYCHO_PCIB_CTRL);
1013 tmp |= (PSYCHO_PCICTRL_SERR |
1014 PSYCHO_PCICTRL_SBH_ERR |
1015 PSYCHO_PCICTRL_EEN);
1016 tmp &= ~(PSYCHO_PCICTRL_SBH_INT);
1017 psycho_write(base + PSYCHO_PCIB_CTRL, tmp);
1020 /* PSYCHO boot time probing and initialization. */
1021 static void psycho_resource_adjust(struct pci_dev *pdev,
1022 struct resource *res,
1023 struct resource *root)
1025 res->start += root->start;
1026 res->end += root->start;
1029 static void psycho_base_address_update(struct pci_dev *pdev, int resource)
1031 struct pcidev_cookie *pcp = pdev->sysdata;
1032 struct pci_pbm_info *pbm = pcp->pbm;
1033 struct resource *res, *root;
1035 int where, size, is_64bit;
1037 res = &pdev->resource[resource];
1039 where = PCI_BASE_ADDRESS_0 + (resource * 4);
1040 } else if (resource == PCI_ROM_RESOURCE) {
1041 where = pdev->rom_base_reg;
1043 /* Somebody might have asked allocation of a non-standard resource */
1048 if (res->flags & IORESOURCE_IO)
1049 root = &pbm->io_space;
1051 root = &pbm->mem_space;
1052 if ((res->flags & PCI_BASE_ADDRESS_MEM_TYPE_MASK)
1053 == PCI_BASE_ADDRESS_MEM_TYPE_64)
1057 size = res->end - res->start;
1058 pci_read_config_dword(pdev, where, ®);
1059 reg = ((reg & size) |
1060 (((u32)(res->start - root->start)) & ~size));
1061 if (resource == PCI_ROM_RESOURCE) {
1062 reg |= PCI_ROM_ADDRESS_ENABLE;
1063 res->flags |= IORESOURCE_ROM_ENABLE;
1065 pci_write_config_dword(pdev, where, reg);
1067 /* This knows that the upper 32-bits of the address
1068 * must be zero. Our PCI common layer enforces this.
1071 pci_write_config_dword(pdev, where + 4, 0);
1074 static void pbm_config_busmastering(struct pci_pbm_info *pbm)
1078 /* Set cache-line size to 64 bytes, this is actually
1079 * a nop but I do it for completeness.
1081 addr = psycho_pci_config_mkaddr(pbm, pbm->pci_first_busno,
1082 0, PCI_CACHE_LINE_SIZE);
1083 pci_config_write8(addr, 64 / sizeof(u32));
1085 /* Set PBM latency timer to 64 PCI clocks. */
1086 addr = psycho_pci_config_mkaddr(pbm, pbm->pci_first_busno,
1087 0, PCI_LATENCY_TIMER);
1088 pci_config_write8(addr, 64);
1091 static void pbm_scan_bus(struct pci_controller_info *p,
1092 struct pci_pbm_info *pbm)
1094 struct pcidev_cookie *cookie = kzalloc(sizeof(*cookie), GFP_KERNEL);
1097 prom_printf("PSYCHO: Critical allocation failure.\n");
1101 /* All we care about is the PBM. */
1104 pbm->pci_bus = pci_scan_bus(pbm->pci_first_busno,
1107 pci_fixup_host_bridge_self(pbm->pci_bus);
1108 pbm->pci_bus->self->sysdata = cookie;
1110 pci_fill_in_pbm_cookies(pbm->pci_bus, pbm, pbm->prom_node);
1111 pci_record_assignments(pbm, pbm->pci_bus);
1112 pci_assign_unassigned(pbm, pbm->pci_bus);
1113 pci_fixup_irq(pbm, pbm->pci_bus);
1114 pci_determine_66mhz_disposition(pbm, pbm->pci_bus);
1115 pci_setup_busmastering(pbm, pbm->pci_bus);
1118 static void psycho_scan_bus(struct pci_controller_info *p)
1120 pbm_config_busmastering(&p->pbm_B);
1121 p->pbm_B.is_66mhz_capable = 0;
1122 pbm_config_busmastering(&p->pbm_A);
1123 p->pbm_A.is_66mhz_capable = 1;
1124 pbm_scan_bus(p, &p->pbm_B);
1125 pbm_scan_bus(p, &p->pbm_A);
1127 /* After the PCI bus scan is complete, we can register
1128 * the error interrupt handlers.
1130 psycho_register_error_handlers(p);
1133 static void psycho_iommu_init(struct pci_controller_info *p)
1135 struct pci_iommu *iommu = p->pbm_A.iommu;
1139 /* Register addresses. */
1140 iommu->iommu_control = p->pbm_A.controller_regs + PSYCHO_IOMMU_CONTROL;
1141 iommu->iommu_tsbbase = p->pbm_A.controller_regs + PSYCHO_IOMMU_TSBBASE;
1142 iommu->iommu_flush = p->pbm_A.controller_regs + PSYCHO_IOMMU_FLUSH;
1143 /* PSYCHO's IOMMU lacks ctx flushing. */
1144 iommu->iommu_ctxflush = 0;
1146 /* We use the main control register of PSYCHO as the write
1147 * completion register.
1149 iommu->write_complete_reg = p->pbm_A.controller_regs + PSYCHO_CONTROL;
1152 * Invalidate TLB Entries.
1154 control = psycho_read(p->pbm_A.controller_regs + PSYCHO_IOMMU_CONTROL);
1155 control |= PSYCHO_IOMMU_CTRL_DENAB;
1156 psycho_write(p->pbm_A.controller_regs + PSYCHO_IOMMU_CONTROL, control);
1157 for(i = 0; i < 16; i++) {
1158 psycho_write(p->pbm_A.controller_regs + PSYCHO_IOMMU_TAG + (i * 8UL), 0);
1159 psycho_write(p->pbm_A.controller_regs + PSYCHO_IOMMU_DATA + (i * 8UL), 0);
1162 /* Leave diag mode enabled for full-flushing done
1165 pci_iommu_table_init(iommu, IO_TSB_SIZE, 0xc0000000, 0xffffffff);
1167 psycho_write(p->pbm_A.controller_regs + PSYCHO_IOMMU_TSBBASE,
1168 __pa(iommu->page_table));
1170 control = psycho_read(p->pbm_A.controller_regs + PSYCHO_IOMMU_CONTROL);
1171 control &= ~(PSYCHO_IOMMU_CTRL_TSBSZ | PSYCHO_IOMMU_CTRL_TBWSZ);
1172 control |= (PSYCHO_IOMMU_TSBSZ_128K | PSYCHO_IOMMU_CTRL_ENAB);
1173 psycho_write(p->pbm_A.controller_regs + PSYCHO_IOMMU_CONTROL, control);
1175 /* If necessary, hook us up for starfire IRQ translations. */
1176 if (this_is_starfire)
1177 p->starfire_cookie = starfire_hookup(p->pbm_A.portid);
1179 p->starfire_cookie = NULL;
1182 #define PSYCHO_IRQ_RETRY 0x1a00UL
1183 #define PSYCHO_PCIA_DIAG 0x2020UL
1184 #define PSYCHO_PCIB_DIAG 0x4020UL
1185 #define PSYCHO_PCIDIAG_RESV 0xffffffffffffff80UL /* Reserved */
1186 #define PSYCHO_PCIDIAG_DRETRY 0x0000000000000040UL /* Disable retry limit */
1187 #define PSYCHO_PCIDIAG_DISYNC 0x0000000000000020UL /* Disable DMA wr / irq sync */
1188 #define PSYCHO_PCIDIAG_DDWSYNC 0x0000000000000010UL /* Disable DMA wr / PIO rd sync */
1189 #define PSYCHO_PCIDIAG_IDDPAR 0x0000000000000008UL /* Invert DMA data parity */
1190 #define PSYCHO_PCIDIAG_IPDPAR 0x0000000000000004UL /* Invert PIO data parity */
1191 #define PSYCHO_PCIDIAG_IPAPAR 0x0000000000000002UL /* Invert PIO address parity */
1192 #define PSYCHO_PCIDIAG_LPBACK 0x0000000000000001UL /* Enable loopback mode */
1194 static void psycho_controller_hwinit(struct pci_controller_info *p)
1198 psycho_write(p->pbm_A.controller_regs + PSYCHO_IRQ_RETRY, 5);
1200 /* Enable arbiter for all PCI slots. */
1201 tmp = psycho_read(p->pbm_A.controller_regs + PSYCHO_PCIA_CTRL);
1202 tmp |= PSYCHO_PCICTRL_AEN;
1203 psycho_write(p->pbm_A.controller_regs + PSYCHO_PCIA_CTRL, tmp);
1205 tmp = psycho_read(p->pbm_A.controller_regs + PSYCHO_PCIB_CTRL);
1206 tmp |= PSYCHO_PCICTRL_AEN;
1207 psycho_write(p->pbm_A.controller_regs + PSYCHO_PCIB_CTRL, tmp);
1209 /* Disable DMA write / PIO read synchronization on
1210 * both PCI bus segments.
1211 * [ U2P Erratum 1243770, STP2223BGA data sheet ]
1213 tmp = psycho_read(p->pbm_A.controller_regs + PSYCHO_PCIA_DIAG);
1214 tmp |= PSYCHO_PCIDIAG_DDWSYNC;
1215 psycho_write(p->pbm_A.controller_regs + PSYCHO_PCIA_DIAG, tmp);
1217 tmp = psycho_read(p->pbm_A.controller_regs + PSYCHO_PCIB_DIAG);
1218 tmp |= PSYCHO_PCIDIAG_DDWSYNC;
1219 psycho_write(p->pbm_A.controller_regs + PSYCHO_PCIB_DIAG, tmp);
1222 static void pbm_register_toplevel_resources(struct pci_controller_info *p,
1223 struct pci_pbm_info *pbm)
1225 char *name = pbm->name;
1227 sprintf(name, "PSYCHO%d PBM%c",
1229 (pbm == &p->pbm_A ? 'A' : 'B'));
1230 pbm->io_space.name = pbm->mem_space.name = name;
1232 request_resource(&ioport_resource, &pbm->io_space);
1233 request_resource(&iomem_resource, &pbm->mem_space);
1234 pci_register_legacy_regions(&pbm->io_space,
1238 static void psycho_pbm_strbuf_init(struct pci_controller_info *p,
1239 struct pci_pbm_info *pbm,
1242 unsigned long base = pbm->controller_regs;
1246 pbm->stc.strbuf_control = base + PSYCHO_STRBUF_CONTROL_A;
1247 pbm->stc.strbuf_pflush = base + PSYCHO_STRBUF_FLUSH_A;
1248 pbm->stc.strbuf_fsync = base + PSYCHO_STRBUF_FSYNC_A;
1250 pbm->stc.strbuf_control = base + PSYCHO_STRBUF_CONTROL_B;
1251 pbm->stc.strbuf_pflush = base + PSYCHO_STRBUF_FLUSH_B;
1252 pbm->stc.strbuf_fsync = base + PSYCHO_STRBUF_FSYNC_B;
1254 /* PSYCHO's streaming buffer lacks ctx flushing. */
1255 pbm->stc.strbuf_ctxflush = 0;
1256 pbm->stc.strbuf_ctxmatch_base = 0;
1258 pbm->stc.strbuf_flushflag = (volatile unsigned long *)
1259 ((((unsigned long)&pbm->stc.__flushflag_buf[0])
1262 pbm->stc.strbuf_flushflag_pa = (unsigned long)
1263 __pa(pbm->stc.strbuf_flushflag);
1265 /* Enable the streaming buffer. We have to be careful
1266 * just in case OBP left it with LRU locking enabled.
1268 * It is possible to control if PBM will be rerun on
1269 * line misses. Currently I just retain whatever setting
1270 * OBP left us with. All checks so far show it having
1273 #undef PSYCHO_STRBUF_RERUN_ENABLE
1274 #undef PSYCHO_STRBUF_RERUN_DISABLE
1275 control = psycho_read(pbm->stc.strbuf_control);
1276 control |= PSYCHO_STRBUF_CTRL_ENAB;
1277 control &= ~(PSYCHO_STRBUF_CTRL_LENAB | PSYCHO_STRBUF_CTRL_LPTR);
1278 #ifdef PSYCHO_STRBUF_RERUN_ENABLE
1279 control &= ~(PSYCHO_STRBUF_CTRL_RRDIS);
1281 #ifdef PSYCHO_STRBUF_RERUN_DISABLE
1282 control |= PSYCHO_STRBUF_CTRL_RRDIS;
1285 psycho_write(pbm->stc.strbuf_control, control);
1287 pbm->stc.strbuf_enabled = 1;
1290 #define PSYCHO_IOSPACE_A 0x002000000UL
1291 #define PSYCHO_IOSPACE_B 0x002010000UL
1292 #define PSYCHO_IOSPACE_SIZE 0x00000ffffUL
1293 #define PSYCHO_MEMSPACE_A 0x100000000UL
1294 #define PSYCHO_MEMSPACE_B 0x180000000UL
1295 #define PSYCHO_MEMSPACE_SIZE 0x07fffffffUL
1297 static void psycho_pbm_init(struct pci_controller_info *p,
1298 int prom_node, int is_pbm_a)
1300 unsigned int busrange[2];
1301 struct pci_pbm_info *pbm;
1306 pbm->pci_first_slot = 1;
1307 pbm->io_space.start = pbm->controller_regs + PSYCHO_IOSPACE_A;
1308 pbm->mem_space.start = pbm->controller_regs + PSYCHO_MEMSPACE_A;
1311 pbm->pci_first_slot = 2;
1312 pbm->io_space.start = pbm->controller_regs + PSYCHO_IOSPACE_B;
1313 pbm->mem_space.start = pbm->controller_regs + PSYCHO_MEMSPACE_B;
1316 pbm->chip_type = PBM_CHIP_TYPE_PSYCHO;
1318 prom_getintdefault(prom_node, "version#", 0);
1319 pbm->chip_revision =
1320 prom_getintdefault(prom_node, "module-revision#", 0);
1322 pbm->io_space.end = pbm->io_space.start + PSYCHO_IOSPACE_SIZE;
1323 pbm->io_space.flags = IORESOURCE_IO;
1324 pbm->mem_space.end = pbm->mem_space.start + PSYCHO_MEMSPACE_SIZE;
1325 pbm->mem_space.flags = IORESOURCE_MEM;
1326 pbm_register_toplevel_resources(p, pbm);
1329 pbm->prom_node = prom_node;
1330 prom_getstring(prom_node, "name",
1332 sizeof(pbm->prom_name));
1334 err = prom_getproperty(prom_node, "ranges",
1335 (char *)pbm->pbm_ranges,
1336 sizeof(pbm->pbm_ranges));
1338 pbm->num_pbm_ranges =
1339 (err / sizeof(struct linux_prom_pci_ranges));
1341 pbm->num_pbm_ranges = 0;
1343 err = prom_getproperty(prom_node, "interrupt-map",
1344 (char *)pbm->pbm_intmap,
1345 sizeof(pbm->pbm_intmap));
1347 pbm->num_pbm_intmap = (err / sizeof(struct linux_prom_pci_intmap));
1348 err = prom_getproperty(prom_node, "interrupt-map-mask",
1349 (char *)&pbm->pbm_intmask,
1350 sizeof(pbm->pbm_intmask));
1352 prom_printf("PSYCHO-PBM: Fatal error, no "
1353 "interrupt-map-mask.\n");
1357 pbm->num_pbm_intmap = 0;
1358 memset(&pbm->pbm_intmask, 0, sizeof(pbm->pbm_intmask));
1361 err = prom_getproperty(prom_node, "bus-range",
1362 (char *)&busrange[0],
1364 if (err == 0 || err == -1) {
1365 prom_printf("PSYCHO-PBM: Fatal error, no bus-range.\n");
1368 pbm->pci_first_busno = busrange[0];
1369 pbm->pci_last_busno = busrange[1];
1371 psycho_pbm_strbuf_init(p, pbm, is_pbm_a);
1374 #define PSYCHO_CONFIGSPACE 0x001000000UL
1376 void psycho_init(int node, char *model_name)
1378 struct linux_prom64_registers pr_regs[3];
1379 struct pci_controller_info *p;
1380 struct pci_iommu *iommu;
1384 upa_portid = prom_getintdefault(node, "upa-portid", 0xff);
1386 for(p = pci_controller_root; p; p = p->next) {
1387 if (p->pbm_A.portid == upa_portid) {
1388 is_pbm_a = (p->pbm_A.prom_node == 0);
1389 psycho_pbm_init(p, node, is_pbm_a);
1394 p = kzalloc(sizeof(struct pci_controller_info), GFP_ATOMIC);
1396 prom_printf("PSYCHO: Fatal memory allocation error.\n");
1399 iommu = kzalloc(sizeof(struct pci_iommu), GFP_ATOMIC);
1401 prom_printf("PSYCHO: Fatal memory allocation error.\n");
1404 p->pbm_A.iommu = p->pbm_B.iommu = iommu;
1406 p->next = pci_controller_root;
1407 pci_controller_root = p;
1409 p->pbm_A.portid = upa_portid;
1410 p->pbm_B.portid = upa_portid;
1411 p->index = pci_num_controllers++;
1412 p->pbms_same_domain = 0;
1413 p->scan_bus = psycho_scan_bus;
1414 p->irq_build = psycho_irq_build;
1415 p->base_address_update = psycho_base_address_update;
1416 p->resource_adjust = psycho_resource_adjust;
1417 p->pci_ops = &psycho_ops;
1419 err = prom_getproperty(node, "reg",
1420 (char *)&pr_regs[0],
1422 if (err == 0 || err == -1) {
1423 prom_printf("PSYCHO: Fatal error, no reg property.\n");
1427 p->pbm_A.controller_regs = pr_regs[2].phys_addr;
1428 p->pbm_B.controller_regs = pr_regs[2].phys_addr;
1429 printk("PCI: Found PSYCHO, control regs at %016lx\n",
1430 p->pbm_A.controller_regs);
1432 p->pbm_A.config_space = p->pbm_B.config_space =
1433 (pr_regs[2].phys_addr + PSYCHO_CONFIGSPACE);
1434 printk("PSYCHO: Shared PCI config space at %016lx\n",
1435 p->pbm_A.config_space);
1438 * Psycho's PCI MEM space is mapped to a 2GB aligned area, so
1439 * we need to adjust our MEM space mask.
1441 pci_memspace_mask = 0x7fffffffUL;
1443 psycho_controller_hwinit(p);
1445 psycho_iommu_init(p);
1447 is_pbm_a = ((pr_regs[0].phys_addr & 0x6000) == 0x2000);
1448 psycho_pbm_init(p, node, is_pbm_a);