]> err.no Git - linux-2.6/blob - arch/sparc64/kernel/pci_schizo.c
[SPARC64]: Kill ino_bucket->pil
[linux-2.6] / arch / sparc64 / kernel / pci_schizo.c
1 /* $Id: pci_schizo.c,v 1.24 2002/01/23 11:27:32 davem Exp $
2  * pci_schizo.c: SCHIZO/TOMATILLO specific PCI controller support.
3  *
4  * Copyright (C) 2001, 2002, 2003 David S. Miller (davem@redhat.com)
5  */
6
7 #include <linux/kernel.h>
8 #include <linux/types.h>
9 #include <linux/pci.h>
10 #include <linux/init.h>
11 #include <linux/slab.h>
12 #include <linux/interrupt.h>
13
14 #include <asm/pbm.h>
15 #include <asm/iommu.h>
16 #include <asm/irq.h>
17 #include <asm/upa.h>
18 #include <asm/pstate.h>
19
20 #include "pci_impl.h"
21 #include "iommu_common.h"
22
23 /* All SCHIZO registers are 64-bits.  The following accessor
24  * routines are how they are accessed.  The REG parameter
25  * is a physical address.
26  */
27 #define schizo_read(__reg) \
28 ({      u64 __ret; \
29         __asm__ __volatile__("ldxa [%1] %2, %0" \
30                              : "=r" (__ret) \
31                              : "r" (__reg), "i" (ASI_PHYS_BYPASS_EC_E) \
32                              : "memory"); \
33         __ret; \
34 })
35 #define schizo_write(__reg, __val) \
36         __asm__ __volatile__("stxa %0, [%1] %2" \
37                              : /* no outputs */ \
38                              : "r" (__val), "r" (__reg), \
39                                "i" (ASI_PHYS_BYPASS_EC_E) \
40                              : "memory")
41
42 /* This is a convention that at least Excalibur and Merlin
43  * follow.  I suppose the SCHIZO used in Starcat and friends
44  * will do similar.
45  *
46  * The only way I could see this changing is if the newlink
47  * block requires more space in Schizo's address space than
48  * they predicted, thus requiring an address space reorg when
49  * the newer Schizo is taped out.
50  */
51
52 /* Streaming buffer control register. */
53 #define SCHIZO_STRBUF_CTRL_LPTR    0x00000000000000f0UL /* LRU Lock Pointer */
54 #define SCHIZO_STRBUF_CTRL_LENAB   0x0000000000000008UL /* LRU Lock Enable */
55 #define SCHIZO_STRBUF_CTRL_RRDIS   0x0000000000000004UL /* Rerun Disable */
56 #define SCHIZO_STRBUF_CTRL_DENAB   0x0000000000000002UL /* Diagnostic Mode Enable */
57 #define SCHIZO_STRBUF_CTRL_ENAB    0x0000000000000001UL /* Streaming Buffer Enable */
58
59 /* IOMMU control register. */
60 #define SCHIZO_IOMMU_CTRL_RESV     0xfffffffff9000000UL /* Reserved                      */
61 #define SCHIZO_IOMMU_CTRL_XLTESTAT 0x0000000006000000UL /* Translation Error Status      */
62 #define SCHIZO_IOMMU_CTRL_XLTEERR  0x0000000001000000UL /* Translation Error encountered */
63 #define SCHIZO_IOMMU_CTRL_LCKEN    0x0000000000800000UL /* Enable translation locking    */
64 #define SCHIZO_IOMMU_CTRL_LCKPTR   0x0000000000780000UL /* Translation lock pointer      */
65 #define SCHIZO_IOMMU_CTRL_TSBSZ    0x0000000000070000UL /* TSB Size                      */
66 #define SCHIZO_IOMMU_TSBSZ_1K      0x0000000000000000UL /* TSB Table 1024 8-byte entries */
67 #define SCHIZO_IOMMU_TSBSZ_2K      0x0000000000010000UL /* TSB Table 2048 8-byte entries */
68 #define SCHIZO_IOMMU_TSBSZ_4K      0x0000000000020000UL /* TSB Table 4096 8-byte entries */
69 #define SCHIZO_IOMMU_TSBSZ_8K      0x0000000000030000UL /* TSB Table 8192 8-byte entries */
70 #define SCHIZO_IOMMU_TSBSZ_16K     0x0000000000040000UL /* TSB Table 16k 8-byte entries  */
71 #define SCHIZO_IOMMU_TSBSZ_32K     0x0000000000050000UL /* TSB Table 32k 8-byte entries  */
72 #define SCHIZO_IOMMU_TSBSZ_64K     0x0000000000060000UL /* TSB Table 64k 8-byte entries  */
73 #define SCHIZO_IOMMU_TSBSZ_128K    0x0000000000070000UL /* TSB Table 128k 8-byte entries */
74 #define SCHIZO_IOMMU_CTRL_RESV2    0x000000000000fff8UL /* Reserved                      */
75 #define SCHIZO_IOMMU_CTRL_TBWSZ    0x0000000000000004UL /* Assumed page size, 0=8k 1=64k */
76 #define SCHIZO_IOMMU_CTRL_DENAB    0x0000000000000002UL /* Diagnostic mode enable        */
77 #define SCHIZO_IOMMU_CTRL_ENAB     0x0000000000000001UL /* IOMMU Enable                  */
78
79 /* Schizo config space address format is nearly identical to
80  * that of PSYCHO:
81  *
82  *  32             24 23 16 15    11 10       8 7   2  1 0
83  * ---------------------------------------------------------
84  * |0 0 0 0 0 0 0 0 0| bus | device | function | reg | 0 0 |
85  * ---------------------------------------------------------
86  */
87 #define SCHIZO_CONFIG_BASE(PBM) ((PBM)->config_space)
88 #define SCHIZO_CONFIG_ENCODE(BUS, DEVFN, REG)   \
89         (((unsigned long)(BUS)   << 16) |       \
90          ((unsigned long)(DEVFN) << 8)  |       \
91          ((unsigned long)(REG)))
92
93 static void *schizo_pci_config_mkaddr(struct pci_pbm_info *pbm,
94                                       unsigned char bus,
95                                       unsigned int devfn,
96                                       int where)
97 {
98         if (!pbm)
99                 return NULL;
100         bus -= pbm->pci_first_busno;
101         return (void *)
102                 (SCHIZO_CONFIG_BASE(pbm) |
103                  SCHIZO_CONFIG_ENCODE(bus, devfn, where));
104 }
105
106 /* Just make sure the bus number is in range.  */
107 static int schizo_out_of_range(struct pci_pbm_info *pbm,
108                                unsigned char bus,
109                                unsigned char devfn)
110 {
111         if (bus < pbm->pci_first_busno ||
112             bus > pbm->pci_last_busno)
113                 return 1;
114         return 0;
115 }
116
117 /* SCHIZO PCI configuration space accessors. */
118
119 static int schizo_read_pci_cfg(struct pci_bus *bus_dev, unsigned int devfn,
120                                int where, int size, u32 *value)
121 {
122         struct pci_pbm_info *pbm = bus_dev->sysdata;
123         unsigned char bus = bus_dev->number;
124         u32 *addr;
125         u16 tmp16;
126         u8 tmp8;
127
128         switch (size) {
129         case 1:
130                 *value = 0xff;
131                 break;
132         case 2:
133                 *value = 0xffff;
134                 break;
135         case 4:
136                 *value = 0xffffffff;
137                 break;
138         }
139
140         addr = schizo_pci_config_mkaddr(pbm, bus, devfn, where);
141         if (!addr)
142                 return PCIBIOS_SUCCESSFUL;
143
144         if (schizo_out_of_range(pbm, bus, devfn))
145                 return PCIBIOS_SUCCESSFUL;
146         switch (size) {
147         case 1:
148                 pci_config_read8((u8 *)addr, &tmp8);
149                 *value = tmp8;
150                 break;
151
152         case 2:
153                 if (where & 0x01) {
154                         printk("pci_read_config_word: misaligned reg [%x]\n",
155                                where);
156                         return PCIBIOS_SUCCESSFUL;
157                 }
158                 pci_config_read16((u16 *)addr, &tmp16);
159                 *value = tmp16;
160                 break;
161
162         case 4:
163                 if (where & 0x03) {
164                         printk("pci_read_config_dword: misaligned reg [%x]\n",
165                                where);
166                         return PCIBIOS_SUCCESSFUL;
167                 }
168                 pci_config_read32(addr, value);
169                 break;
170         }
171         return PCIBIOS_SUCCESSFUL;
172 }
173
174 static int schizo_write_pci_cfg(struct pci_bus *bus_dev, unsigned int devfn,
175                                 int where, int size, u32 value)
176 {
177         struct pci_pbm_info *pbm = bus_dev->sysdata;
178         unsigned char bus = bus_dev->number;
179         u32 *addr;
180
181         addr = schizo_pci_config_mkaddr(pbm, bus, devfn, where);
182         if (!addr)
183                 return PCIBIOS_SUCCESSFUL;
184
185         if (schizo_out_of_range(pbm, bus, devfn))
186                 return PCIBIOS_SUCCESSFUL;
187
188         switch (size) {
189         case 1:
190                 pci_config_write8((u8 *)addr, value);
191                 break;
192
193         case 2:
194                 if (where & 0x01) {
195                         printk("pci_write_config_word: misaligned reg [%x]\n",
196                                where);
197                         return PCIBIOS_SUCCESSFUL;
198                 }
199                 pci_config_write16((u16 *)addr, value);
200                 break;
201
202         case 4:
203                 if (where & 0x03) {
204                         printk("pci_write_config_dword: misaligned reg [%x]\n",
205                                where);
206                         return PCIBIOS_SUCCESSFUL;
207                 }
208
209                 pci_config_write32(addr, value);
210         }
211         return PCIBIOS_SUCCESSFUL;
212 }
213
214 static struct pci_ops schizo_ops = {
215         .read =         schizo_read_pci_cfg,
216         .write =        schizo_write_pci_cfg,
217 };
218
219 /* SCHIZO interrupt mapping support.  Unlike Psycho, for this controller the
220  * imap/iclr registers are per-PBM.
221  */
222 #define SCHIZO_IMAP_BASE        0x1000UL
223 #define SCHIZO_ICLR_BASE        0x1400UL
224
225 static unsigned long schizo_imap_offset(unsigned long ino)
226 {
227         return SCHIZO_IMAP_BASE + (ino * 8UL);
228 }
229
230 static unsigned long schizo_iclr_offset(unsigned long ino)
231 {
232         return SCHIZO_ICLR_BASE + (ino * 8UL);
233 }
234
235 static void tomatillo_wsync_handler(struct ino_bucket *bucket, void *_arg1, void *_arg2)
236 {
237         unsigned long sync_reg = (unsigned long) _arg2;
238         u64 mask = 1UL << (__irq_ino(__irq(bucket)) & IMAP_INO);
239         u64 val;
240         int limit;
241
242         schizo_write(sync_reg, mask);
243
244         limit = 100000;
245         val = 0;
246         while (--limit) {
247                 val = schizo_read(sync_reg);
248                 if (!(val & mask))
249                         break;
250         }
251         if (limit <= 0) {
252                 printk("tomatillo_wsync_handler: DMA won't sync [%lx:%lx]\n",
253                        val, mask);
254         }
255
256         if (_arg1) {
257                 static unsigned char cacheline[64]
258                         __attribute__ ((aligned (64)));
259
260                 __asm__ __volatile__("rd %%fprs, %0\n\t"
261                                      "or %0, %4, %1\n\t"
262                                      "wr %1, 0x0, %%fprs\n\t"
263                                      "stda %%f0, [%5] %6\n\t"
264                                      "wr %0, 0x0, %%fprs\n\t"
265                                      "membar #Sync"
266                                      : "=&r" (mask), "=&r" (val)
267                                      : "0" (mask), "1" (val),
268                                      "i" (FPRS_FEF), "r" (&cacheline[0]),
269                                      "i" (ASI_BLK_COMMIT_P));
270         }
271 }
272
273 static unsigned int schizo_irq_build(struct pci_pbm_info *pbm,
274                                      struct pci_dev *pdev,
275                                      unsigned int ino)
276 {
277         struct ino_bucket *bucket;
278         unsigned long imap, iclr;
279         unsigned long imap_off, iclr_off;
280         int ign_fixup;
281
282         ino &= PCI_IRQ_INO;
283         imap_off = schizo_imap_offset(ino);
284
285         /* Now build the IRQ bucket. */
286         imap = pbm->pbm_regs + imap_off;
287         imap += 4;
288
289         iclr_off = schizo_iclr_offset(ino);
290         iclr = pbm->pbm_regs + iclr_off;
291         iclr += 4;
292
293         /* On Schizo, no inofixup occurs.  This is because each
294          * INO has it's own IMAP register.  On Psycho and Sabre
295          * there is only one IMAP register for each PCI slot even
296          * though four different INOs can be generated by each
297          * PCI slot.
298          *
299          * But, for JBUS variants (essentially, Tomatillo), we have
300          * to fixup the lowest bit of the interrupt group number.
301          */
302         ign_fixup = 0;
303         if (pbm->chip_type == PBM_CHIP_TYPE_TOMATILLO) {
304                 if (pbm->portid & 1)
305                         ign_fixup = (1 << 6);
306         }
307
308         bucket = __bucket(build_irq(ign_fixup, iclr, imap));
309         bucket->flags |= IBF_PCI;
310
311         if (pdev && pbm->chip_type == PBM_CHIP_TYPE_TOMATILLO) {
312                 struct irq_desc *p = bucket->irq_info;
313
314                 p->pre_handler = tomatillo_wsync_handler;
315                 p->pre_handler_arg1 = ((pbm->chip_version <= 4) ?
316                                        (void *) 1 : (void *) 0);
317                 p->pre_handler_arg2 = (void *) pbm->sync_reg;
318         }
319
320         return __irq(bucket);
321 }
322
323 /* SCHIZO error handling support. */
324 enum schizo_error_type {
325         UE_ERR, CE_ERR, PCI_ERR, SAFARI_ERR
326 };
327
328 static DEFINE_SPINLOCK(stc_buf_lock);
329 static unsigned long stc_error_buf[128];
330 static unsigned long stc_tag_buf[16];
331 static unsigned long stc_line_buf[16];
332
333 #define SCHIZO_UE_INO           0x30 /* Uncorrectable ECC error */
334 #define SCHIZO_CE_INO           0x31 /* Correctable ECC error */
335 #define SCHIZO_PCIERR_A_INO     0x32 /* PBM A PCI bus error */
336 #define SCHIZO_PCIERR_B_INO     0x33 /* PBM B PCI bus error */
337 #define SCHIZO_SERR_INO         0x34 /* Safari interface error */
338
339 struct pci_pbm_info *pbm_for_ino(struct pci_controller_info *p, u32 ino)
340 {
341         ino &= IMAP_INO;
342         if (p->pbm_A.ino_bitmap & (1UL << ino))
343                 return &p->pbm_A;
344         if (p->pbm_B.ino_bitmap & (1UL << ino))
345                 return &p->pbm_B;
346
347         printk("PCI%d: No ino_bitmap entry for ino[%x], bitmaps "
348                "PBM_A[%016lx] PBM_B[%016lx]",
349                p->index, ino,
350                p->pbm_A.ino_bitmap,
351                p->pbm_B.ino_bitmap);
352         printk("PCI%d: Using PBM_A, report this problem immediately.\n",
353                p->index);
354
355         return &p->pbm_A;
356 }
357
358 static void schizo_clear_other_err_intr(struct pci_controller_info *p, int irq)
359 {
360         struct pci_pbm_info *pbm;
361         struct ino_bucket *bucket;
362         unsigned long iclr;
363
364         /* Do not clear the interrupt for the other PCI bus.
365          *
366          * This "ACK both PBM IRQs" only needs to be performed
367          * for chip-wide error interrupts.
368          */
369         if ((irq & IMAP_INO) == SCHIZO_PCIERR_A_INO ||
370             (irq & IMAP_INO) == SCHIZO_PCIERR_B_INO)
371                 return;
372
373         pbm = pbm_for_ino(p, irq);
374         if (pbm == &p->pbm_A)
375                 pbm = &p->pbm_B;
376         else
377                 pbm = &p->pbm_A;
378
379         irq = schizo_irq_build(pbm, NULL,
380                                (pbm->portid << 6) | (irq & IMAP_INO));
381         bucket = __bucket(irq);
382         iclr = bucket->iclr;
383
384         upa_writel(ICLR_IDLE, iclr);
385 }
386
387 #define SCHIZO_STC_ERR  0xb800UL /* --> 0xba00 */
388 #define SCHIZO_STC_TAG  0xba00UL /* --> 0xba80 */
389 #define SCHIZO_STC_LINE 0xbb00UL /* --> 0xbb80 */
390
391 #define SCHIZO_STCERR_WRITE     0x2UL
392 #define SCHIZO_STCERR_READ      0x1UL
393
394 #define SCHIZO_STCTAG_PPN       0x3fffffff00000000UL
395 #define SCHIZO_STCTAG_VPN       0x00000000ffffe000UL
396 #define SCHIZO_STCTAG_VALID     0x8000000000000000UL
397 #define SCHIZO_STCTAG_READ      0x4000000000000000UL
398
399 #define SCHIZO_STCLINE_LINDX    0x0000000007800000UL
400 #define SCHIZO_STCLINE_SPTR     0x000000000007e000UL
401 #define SCHIZO_STCLINE_LADDR    0x0000000000001fc0UL
402 #define SCHIZO_STCLINE_EPTR     0x000000000000003fUL
403 #define SCHIZO_STCLINE_VALID    0x0000000000600000UL
404 #define SCHIZO_STCLINE_FOFN     0x0000000000180000UL
405
406 static void __schizo_check_stc_error_pbm(struct pci_pbm_info *pbm,
407                                          enum schizo_error_type type)
408 {
409         struct pci_strbuf *strbuf = &pbm->stc;
410         unsigned long regbase = pbm->pbm_regs;
411         unsigned long err_base, tag_base, line_base;
412         u64 control;
413         int i;
414
415         err_base = regbase + SCHIZO_STC_ERR;
416         tag_base = regbase + SCHIZO_STC_TAG;
417         line_base = regbase + SCHIZO_STC_LINE;
418
419         spin_lock(&stc_buf_lock);
420
421         /* This is __REALLY__ dangerous.  When we put the
422          * streaming buffer into diagnostic mode to probe
423          * it's tags and error status, we _must_ clear all
424          * of the line tag valid bits before re-enabling
425          * the streaming buffer.  If any dirty data lives
426          * in the STC when we do this, we will end up
427          * invalidating it before it has a chance to reach
428          * main memory.
429          */
430         control = schizo_read(strbuf->strbuf_control);
431         schizo_write(strbuf->strbuf_control,
432                      (control | SCHIZO_STRBUF_CTRL_DENAB));
433         for (i = 0; i < 128; i++) {
434                 unsigned long val;
435
436                 val = schizo_read(err_base + (i * 8UL));
437                 schizo_write(err_base + (i * 8UL), 0UL);
438                 stc_error_buf[i] = val;
439         }
440         for (i = 0; i < 16; i++) {
441                 stc_tag_buf[i] = schizo_read(tag_base + (i * 8UL));
442                 stc_line_buf[i] = schizo_read(line_base + (i * 8UL));
443                 schizo_write(tag_base + (i * 8UL), 0UL);
444                 schizo_write(line_base + (i * 8UL), 0UL);
445         }
446
447         /* OK, state is logged, exit diagnostic mode. */
448         schizo_write(strbuf->strbuf_control, control);
449
450         for (i = 0; i < 16; i++) {
451                 int j, saw_error, first, last;
452
453                 saw_error = 0;
454                 first = i * 8;
455                 last = first + 8;
456                 for (j = first; j < last; j++) {
457                         unsigned long errval = stc_error_buf[j];
458                         if (errval != 0) {
459                                 saw_error++;
460                                 printk("%s: STC_ERR(%d)[wr(%d)rd(%d)]\n",
461                                        pbm->name,
462                                        j,
463                                        (errval & SCHIZO_STCERR_WRITE) ? 1 : 0,
464                                        (errval & SCHIZO_STCERR_READ) ? 1 : 0);
465                         }
466                 }
467                 if (saw_error != 0) {
468                         unsigned long tagval = stc_tag_buf[i];
469                         unsigned long lineval = stc_line_buf[i];
470                         printk("%s: STC_TAG(%d)[PA(%016lx)VA(%08lx)V(%d)R(%d)]\n",
471                                pbm->name,
472                                i,
473                                ((tagval & SCHIZO_STCTAG_PPN) >> 19UL),
474                                (tagval & SCHIZO_STCTAG_VPN),
475                                ((tagval & SCHIZO_STCTAG_VALID) ? 1 : 0),
476                                ((tagval & SCHIZO_STCTAG_READ) ? 1 : 0));
477
478                         /* XXX Should spit out per-bank error information... -DaveM */
479                         printk("%s: STC_LINE(%d)[LIDX(%lx)SP(%lx)LADDR(%lx)EP(%lx)"
480                                "V(%d)FOFN(%d)]\n",
481                                pbm->name,
482                                i,
483                                ((lineval & SCHIZO_STCLINE_LINDX) >> 23UL),
484                                ((lineval & SCHIZO_STCLINE_SPTR) >> 13UL),
485                                ((lineval & SCHIZO_STCLINE_LADDR) >> 6UL),
486                                ((lineval & SCHIZO_STCLINE_EPTR) >> 0UL),
487                                ((lineval & SCHIZO_STCLINE_VALID) ? 1 : 0),
488                                ((lineval & SCHIZO_STCLINE_FOFN) ? 1 : 0));
489                 }
490         }
491
492         spin_unlock(&stc_buf_lock);
493 }
494
495 /* IOMMU is per-PBM in Schizo, so interrogate both for anonymous
496  * controller level errors.
497  */
498
499 #define SCHIZO_IOMMU_TAG        0xa580UL
500 #define SCHIZO_IOMMU_DATA       0xa600UL
501
502 #define SCHIZO_IOMMU_TAG_CTXT   0x0000001ffe000000UL
503 #define SCHIZO_IOMMU_TAG_ERRSTS 0x0000000001800000UL
504 #define SCHIZO_IOMMU_TAG_ERR    0x0000000000400000UL
505 #define SCHIZO_IOMMU_TAG_WRITE  0x0000000000200000UL
506 #define SCHIZO_IOMMU_TAG_STREAM 0x0000000000100000UL
507 #define SCHIZO_IOMMU_TAG_SIZE   0x0000000000080000UL
508 #define SCHIZO_IOMMU_TAG_VPAGE  0x000000000007ffffUL
509
510 #define SCHIZO_IOMMU_DATA_VALID 0x0000000100000000UL
511 #define SCHIZO_IOMMU_DATA_CACHE 0x0000000040000000UL
512 #define SCHIZO_IOMMU_DATA_PPAGE 0x000000003fffffffUL
513
514 static void schizo_check_iommu_error_pbm(struct pci_pbm_info *pbm,
515                                          enum schizo_error_type type)
516 {
517         struct pci_iommu *iommu = pbm->iommu;
518         unsigned long iommu_tag[16];
519         unsigned long iommu_data[16];
520         unsigned long flags;
521         u64 control;
522         int i;
523
524         spin_lock_irqsave(&iommu->lock, flags);
525         control = schizo_read(iommu->iommu_control);
526         if (control & SCHIZO_IOMMU_CTRL_XLTEERR) {
527                 unsigned long base;
528                 char *type_string;
529
530                 /* Clear the error encountered bit. */
531                 control &= ~SCHIZO_IOMMU_CTRL_XLTEERR;
532                 schizo_write(iommu->iommu_control, control);
533
534                 switch((control & SCHIZO_IOMMU_CTRL_XLTESTAT) >> 25UL) {
535                 case 0:
536                         type_string = "Protection Error";
537                         break;
538                 case 1:
539                         type_string = "Invalid Error";
540                         break;
541                 case 2:
542                         type_string = "TimeOut Error";
543                         break;
544                 case 3:
545                 default:
546                         type_string = "ECC Error";
547                         break;
548                 };
549                 printk("%s: IOMMU Error, type[%s]\n",
550                        pbm->name, type_string);
551
552                 /* Put the IOMMU into diagnostic mode and probe
553                  * it's TLB for entries with error status.
554                  *
555                  * It is very possible for another DVMA to occur
556                  * while we do this probe, and corrupt the system
557                  * further.  But we are so screwed at this point
558                  * that we are likely to crash hard anyways, so
559                  * get as much diagnostic information to the
560                  * console as we can.
561                  */
562                 schizo_write(iommu->iommu_control,
563                              control | SCHIZO_IOMMU_CTRL_DENAB);
564
565                 base = pbm->pbm_regs;
566
567                 for (i = 0; i < 16; i++) {
568                         iommu_tag[i] =
569                                 schizo_read(base + SCHIZO_IOMMU_TAG + (i * 8UL));
570                         iommu_data[i] =
571                                 schizo_read(base + SCHIZO_IOMMU_DATA + (i * 8UL));
572
573                         /* Now clear out the entry. */
574                         schizo_write(base + SCHIZO_IOMMU_TAG + (i * 8UL), 0);
575                         schizo_write(base + SCHIZO_IOMMU_DATA + (i * 8UL), 0);
576                 }
577
578                 /* Leave diagnostic mode. */
579                 schizo_write(iommu->iommu_control, control);
580
581                 for (i = 0; i < 16; i++) {
582                         unsigned long tag, data;
583
584                         tag = iommu_tag[i];
585                         if (!(tag & SCHIZO_IOMMU_TAG_ERR))
586                                 continue;
587
588                         data = iommu_data[i];
589                         switch((tag & SCHIZO_IOMMU_TAG_ERRSTS) >> 23UL) {
590                         case 0:
591                                 type_string = "Protection Error";
592                                 break;
593                         case 1:
594                                 type_string = "Invalid Error";
595                                 break;
596                         case 2:
597                                 type_string = "TimeOut Error";
598                                 break;
599                         case 3:
600                         default:
601                                 type_string = "ECC Error";
602                                 break;
603                         };
604                         printk("%s: IOMMU TAG(%d)[error(%s) ctx(%x) wr(%d) str(%d) "
605                                "sz(%dK) vpg(%08lx)]\n",
606                                pbm->name, i, type_string,
607                                (int)((tag & SCHIZO_IOMMU_TAG_CTXT) >> 25UL),
608                                ((tag & SCHIZO_IOMMU_TAG_WRITE) ? 1 : 0),
609                                ((tag & SCHIZO_IOMMU_TAG_STREAM) ? 1 : 0),
610                                ((tag & SCHIZO_IOMMU_TAG_SIZE) ? 64 : 8),
611                                (tag & SCHIZO_IOMMU_TAG_VPAGE) << IOMMU_PAGE_SHIFT);
612                         printk("%s: IOMMU DATA(%d)[valid(%d) cache(%d) ppg(%016lx)]\n",
613                                pbm->name, i,
614                                ((data & SCHIZO_IOMMU_DATA_VALID) ? 1 : 0),
615                                ((data & SCHIZO_IOMMU_DATA_CACHE) ? 1 : 0),
616                                (data & SCHIZO_IOMMU_DATA_PPAGE) << IOMMU_PAGE_SHIFT);
617                 }
618         }
619         if (pbm->stc.strbuf_enabled)
620                 __schizo_check_stc_error_pbm(pbm, type);
621         spin_unlock_irqrestore(&iommu->lock, flags);
622 }
623
624 static void schizo_check_iommu_error(struct pci_controller_info *p,
625                                      enum schizo_error_type type)
626 {
627         schizo_check_iommu_error_pbm(&p->pbm_A, type);
628         schizo_check_iommu_error_pbm(&p->pbm_B, type);
629 }
630
631 /* Uncorrectable ECC error status gathering. */
632 #define SCHIZO_UE_AFSR  0x10030UL
633 #define SCHIZO_UE_AFAR  0x10038UL
634
635 #define SCHIZO_UEAFSR_PPIO      0x8000000000000000UL /* Safari */
636 #define SCHIZO_UEAFSR_PDRD      0x4000000000000000UL /* Safari/Tomatillo */
637 #define SCHIZO_UEAFSR_PDWR      0x2000000000000000UL /* Safari */
638 #define SCHIZO_UEAFSR_SPIO      0x1000000000000000UL /* Safari */
639 #define SCHIZO_UEAFSR_SDMA      0x0800000000000000UL /* Safari/Tomatillo */
640 #define SCHIZO_UEAFSR_ERRPNDG   0x0300000000000000UL /* Safari */
641 #define SCHIZO_UEAFSR_BMSK      0x000003ff00000000UL /* Safari */
642 #define SCHIZO_UEAFSR_QOFF      0x00000000c0000000UL /* Safari/Tomatillo */
643 #define SCHIZO_UEAFSR_AID       0x000000001f000000UL /* Safari/Tomatillo */
644 #define SCHIZO_UEAFSR_PARTIAL   0x0000000000800000UL /* Safari */
645 #define SCHIZO_UEAFSR_OWNEDIN   0x0000000000400000UL /* Safari */
646 #define SCHIZO_UEAFSR_MTAGSYND  0x00000000000f0000UL /* Safari */
647 #define SCHIZO_UEAFSR_MTAG      0x000000000000e000UL /* Safari */
648 #define SCHIZO_UEAFSR_ECCSYND   0x00000000000001ffUL /* Safari */
649
650 static irqreturn_t schizo_ue_intr(int irq, void *dev_id, struct pt_regs *regs)
651 {
652         struct pci_controller_info *p = dev_id;
653         unsigned long afsr_reg = p->pbm_B.controller_regs + SCHIZO_UE_AFSR;
654         unsigned long afar_reg = p->pbm_B.controller_regs + SCHIZO_UE_AFAR;
655         unsigned long afsr, afar, error_bits;
656         int reported, limit;
657
658         /* Latch uncorrectable error status. */
659         afar = schizo_read(afar_reg);
660
661         /* If either of the error pending bits are set in the
662          * AFSR, the error status is being actively updated by
663          * the hardware and we must re-read to get a clean value.
664          */
665         limit = 1000;
666         do {
667                 afsr = schizo_read(afsr_reg);
668         } while ((afsr & SCHIZO_UEAFSR_ERRPNDG) != 0 && --limit);
669
670         /* Clear the primary/secondary error status bits. */
671         error_bits = afsr &
672                 (SCHIZO_UEAFSR_PPIO | SCHIZO_UEAFSR_PDRD | SCHIZO_UEAFSR_PDWR |
673                  SCHIZO_UEAFSR_SPIO | SCHIZO_UEAFSR_SDMA);
674         if (!error_bits)
675                 return IRQ_NONE;
676         schizo_write(afsr_reg, error_bits);
677
678         /* Log the error. */
679         printk("PCI%d: Uncorrectable Error, primary error type[%s]\n",
680                p->index,
681                (((error_bits & SCHIZO_UEAFSR_PPIO) ?
682                  "PIO" :
683                  ((error_bits & SCHIZO_UEAFSR_PDRD) ?
684                   "DMA Read" :
685                   ((error_bits & SCHIZO_UEAFSR_PDWR) ?
686                    "DMA Write" : "???")))));
687         printk("PCI%d: bytemask[%04lx] qword_offset[%lx] SAFARI_AID[%02lx]\n",
688                p->index,
689                (afsr & SCHIZO_UEAFSR_BMSK) >> 32UL,
690                (afsr & SCHIZO_UEAFSR_QOFF) >> 30UL,
691                (afsr & SCHIZO_UEAFSR_AID) >> 24UL);
692         printk("PCI%d: partial[%d] owned_in[%d] mtag[%lx] mtag_synd[%lx] ecc_sync[%lx]\n",
693                p->index,
694                (afsr & SCHIZO_UEAFSR_PARTIAL) ? 1 : 0,
695                (afsr & SCHIZO_UEAFSR_OWNEDIN) ? 1 : 0,
696                (afsr & SCHIZO_UEAFSR_MTAG) >> 13UL,
697                (afsr & SCHIZO_UEAFSR_MTAGSYND) >> 16UL,
698                (afsr & SCHIZO_UEAFSR_ECCSYND) >> 0UL);
699         printk("PCI%d: UE AFAR [%016lx]\n", p->index, afar);
700         printk("PCI%d: UE Secondary errors [", p->index);
701         reported = 0;
702         if (afsr & SCHIZO_UEAFSR_SPIO) {
703                 reported++;
704                 printk("(PIO)");
705         }
706         if (afsr & SCHIZO_UEAFSR_SDMA) {
707                 reported++;
708                 printk("(DMA)");
709         }
710         if (!reported)
711                 printk("(none)");
712         printk("]\n");
713
714         /* Interrogate IOMMU for error status. */
715         schizo_check_iommu_error(p, UE_ERR);
716
717         schizo_clear_other_err_intr(p, irq);
718
719         return IRQ_HANDLED;
720 }
721
722 #define SCHIZO_CE_AFSR  0x10040UL
723 #define SCHIZO_CE_AFAR  0x10048UL
724
725 #define SCHIZO_CEAFSR_PPIO      0x8000000000000000UL
726 #define SCHIZO_CEAFSR_PDRD      0x4000000000000000UL
727 #define SCHIZO_CEAFSR_PDWR      0x2000000000000000UL
728 #define SCHIZO_CEAFSR_SPIO      0x1000000000000000UL
729 #define SCHIZO_CEAFSR_SDMA      0x0800000000000000UL
730 #define SCHIZO_CEAFSR_ERRPNDG   0x0300000000000000UL
731 #define SCHIZO_CEAFSR_BMSK      0x000003ff00000000UL
732 #define SCHIZO_CEAFSR_QOFF      0x00000000c0000000UL
733 #define SCHIZO_CEAFSR_AID       0x000000001f000000UL
734 #define SCHIZO_CEAFSR_PARTIAL   0x0000000000800000UL
735 #define SCHIZO_CEAFSR_OWNEDIN   0x0000000000400000UL
736 #define SCHIZO_CEAFSR_MTAGSYND  0x00000000000f0000UL
737 #define SCHIZO_CEAFSR_MTAG      0x000000000000e000UL
738 #define SCHIZO_CEAFSR_ECCSYND   0x00000000000001ffUL
739
740 static irqreturn_t schizo_ce_intr(int irq, void *dev_id, struct pt_regs *regs)
741 {
742         struct pci_controller_info *p = dev_id;
743         unsigned long afsr_reg = p->pbm_B.controller_regs + SCHIZO_CE_AFSR;
744         unsigned long afar_reg = p->pbm_B.controller_regs + SCHIZO_CE_AFAR;
745         unsigned long afsr, afar, error_bits;
746         int reported, limit;
747
748         /* Latch error status. */
749         afar = schizo_read(afar_reg);
750
751         /* If either of the error pending bits are set in the
752          * AFSR, the error status is being actively updated by
753          * the hardware and we must re-read to get a clean value.
754          */
755         limit = 1000;
756         do {
757                 afsr = schizo_read(afsr_reg);
758         } while ((afsr & SCHIZO_UEAFSR_ERRPNDG) != 0 && --limit);
759
760         /* Clear primary/secondary error status bits. */
761         error_bits = afsr &
762                 (SCHIZO_CEAFSR_PPIO | SCHIZO_CEAFSR_PDRD | SCHIZO_CEAFSR_PDWR |
763                  SCHIZO_CEAFSR_SPIO | SCHIZO_CEAFSR_SDMA);
764         if (!error_bits)
765                 return IRQ_NONE;
766         schizo_write(afsr_reg, error_bits);
767
768         /* Log the error. */
769         printk("PCI%d: Correctable Error, primary error type[%s]\n",
770                p->index,
771                (((error_bits & SCHIZO_CEAFSR_PPIO) ?
772                  "PIO" :
773                  ((error_bits & SCHIZO_CEAFSR_PDRD) ?
774                   "DMA Read" :
775                   ((error_bits & SCHIZO_CEAFSR_PDWR) ?
776                    "DMA Write" : "???")))));
777
778         /* XXX Use syndrome and afar to print out module string just like
779          * XXX UDB CE trap handler does... -DaveM
780          */
781         printk("PCI%d: bytemask[%04lx] qword_offset[%lx] SAFARI_AID[%02lx]\n",
782                p->index,
783                (afsr & SCHIZO_UEAFSR_BMSK) >> 32UL,
784                (afsr & SCHIZO_UEAFSR_QOFF) >> 30UL,
785                (afsr & SCHIZO_UEAFSR_AID) >> 24UL);
786         printk("PCI%d: partial[%d] owned_in[%d] mtag[%lx] mtag_synd[%lx] ecc_sync[%lx]\n",
787                p->index,
788                (afsr & SCHIZO_UEAFSR_PARTIAL) ? 1 : 0,
789                (afsr & SCHIZO_UEAFSR_OWNEDIN) ? 1 : 0,
790                (afsr & SCHIZO_UEAFSR_MTAG) >> 13UL,
791                (afsr & SCHIZO_UEAFSR_MTAGSYND) >> 16UL,
792                (afsr & SCHIZO_UEAFSR_ECCSYND) >> 0UL);
793         printk("PCI%d: CE AFAR [%016lx]\n", p->index, afar);
794         printk("PCI%d: CE Secondary errors [", p->index);
795         reported = 0;
796         if (afsr & SCHIZO_CEAFSR_SPIO) {
797                 reported++;
798                 printk("(PIO)");
799         }
800         if (afsr & SCHIZO_CEAFSR_SDMA) {
801                 reported++;
802                 printk("(DMA)");
803         }
804         if (!reported)
805                 printk("(none)");
806         printk("]\n");
807
808         schizo_clear_other_err_intr(p, irq);
809
810         return IRQ_HANDLED;
811 }
812
813 #define SCHIZO_PCI_AFSR 0x2010UL
814 #define SCHIZO_PCI_AFAR 0x2018UL
815
816 #define SCHIZO_PCIAFSR_PMA      0x8000000000000000UL /* Schizo/Tomatillo */
817 #define SCHIZO_PCIAFSR_PTA      0x4000000000000000UL /* Schizo/Tomatillo */
818 #define SCHIZO_PCIAFSR_PRTRY    0x2000000000000000UL /* Schizo/Tomatillo */
819 #define SCHIZO_PCIAFSR_PPERR    0x1000000000000000UL /* Schizo/Tomatillo */
820 #define SCHIZO_PCIAFSR_PTTO     0x0800000000000000UL /* Schizo/Tomatillo */
821 #define SCHIZO_PCIAFSR_PUNUS    0x0400000000000000UL /* Schizo */
822 #define SCHIZO_PCIAFSR_SMA      0x0200000000000000UL /* Schizo/Tomatillo */
823 #define SCHIZO_PCIAFSR_STA      0x0100000000000000UL /* Schizo/Tomatillo */
824 #define SCHIZO_PCIAFSR_SRTRY    0x0080000000000000UL /* Schizo/Tomatillo */
825 #define SCHIZO_PCIAFSR_SPERR    0x0040000000000000UL /* Schizo/Tomatillo */
826 #define SCHIZO_PCIAFSR_STTO     0x0020000000000000UL /* Schizo/Tomatillo */
827 #define SCHIZO_PCIAFSR_SUNUS    0x0010000000000000UL /* Schizo */
828 #define SCHIZO_PCIAFSR_BMSK     0x000003ff00000000UL /* Schizo/Tomatillo */
829 #define SCHIZO_PCIAFSR_BLK      0x0000000080000000UL /* Schizo/Tomatillo */
830 #define SCHIZO_PCIAFSR_CFG      0x0000000040000000UL /* Schizo/Tomatillo */
831 #define SCHIZO_PCIAFSR_MEM      0x0000000020000000UL /* Schizo/Tomatillo */
832 #define SCHIZO_PCIAFSR_IO       0x0000000010000000UL /* Schizo/Tomatillo */
833
834 #define SCHIZO_PCI_CTRL         (0x2000UL)
835 #define SCHIZO_PCICTRL_BUS_UNUS (1UL << 63UL) /* Safari */
836 #define SCHIZO_PCICTRL_DTO_INT  (1UL << 61UL) /* Tomatillo */
837 #define SCHIZO_PCICTRL_ARB_PRIO (0x1ff << 52UL) /* Tomatillo */
838 #define SCHIZO_PCICTRL_ESLCK    (1UL << 51UL) /* Safari */
839 #define SCHIZO_PCICTRL_ERRSLOT  (7UL << 48UL) /* Safari */
840 #define SCHIZO_PCICTRL_TTO_ERR  (1UL << 38UL) /* Safari/Tomatillo */
841 #define SCHIZO_PCICTRL_RTRY_ERR (1UL << 37UL) /* Safari/Tomatillo */
842 #define SCHIZO_PCICTRL_DTO_ERR  (1UL << 36UL) /* Safari/Tomatillo */
843 #define SCHIZO_PCICTRL_SBH_ERR  (1UL << 35UL) /* Safari */
844 #define SCHIZO_PCICTRL_SERR     (1UL << 34UL) /* Safari/Tomatillo */
845 #define SCHIZO_PCICTRL_PCISPD   (1UL << 33UL) /* Safari */
846 #define SCHIZO_PCICTRL_MRM_PREF (1UL << 30UL) /* Tomatillo */
847 #define SCHIZO_PCICTRL_RDO_PREF (1UL << 29UL) /* Tomatillo */
848 #define SCHIZO_PCICTRL_RDL_PREF (1UL << 28UL) /* Tomatillo */
849 #define SCHIZO_PCICTRL_PTO      (3UL << 24UL) /* Safari/Tomatillo */
850 #define SCHIZO_PCICTRL_PTO_SHIFT 24UL
851 #define SCHIZO_PCICTRL_TRWSW    (7UL << 21UL) /* Tomatillo */
852 #define SCHIZO_PCICTRL_F_TGT_A  (1UL << 20UL) /* Tomatillo */
853 #define SCHIZO_PCICTRL_S_DTO_INT (1UL << 19UL) /* Safari */
854 #define SCHIZO_PCICTRL_F_TGT_RT (1UL << 19UL) /* Tomatillo */
855 #define SCHIZO_PCICTRL_SBH_INT  (1UL << 18UL) /* Safari */
856 #define SCHIZO_PCICTRL_T_DTO_INT (1UL << 18UL) /* Tomatillo */
857 #define SCHIZO_PCICTRL_EEN      (1UL << 17UL) /* Safari/Tomatillo */
858 #define SCHIZO_PCICTRL_PARK     (1UL << 16UL) /* Safari/Tomatillo */
859 #define SCHIZO_PCICTRL_PCIRST   (1UL <<  8UL) /* Safari */
860 #define SCHIZO_PCICTRL_ARB_S    (0x3fUL << 0UL) /* Safari */
861 #define SCHIZO_PCICTRL_ARB_T    (0xffUL << 0UL) /* Tomatillo */
862
863 static irqreturn_t schizo_pcierr_intr_other(struct pci_pbm_info *pbm)
864 {
865         unsigned long csr_reg, csr, csr_error_bits;
866         irqreturn_t ret = IRQ_NONE;
867         u16 stat;
868
869         csr_reg = pbm->pbm_regs + SCHIZO_PCI_CTRL;
870         csr = schizo_read(csr_reg);
871         csr_error_bits =
872                 csr & (SCHIZO_PCICTRL_BUS_UNUS |
873                        SCHIZO_PCICTRL_TTO_ERR |
874                        SCHIZO_PCICTRL_RTRY_ERR |
875                        SCHIZO_PCICTRL_DTO_ERR |
876                        SCHIZO_PCICTRL_SBH_ERR |
877                        SCHIZO_PCICTRL_SERR);
878         if (csr_error_bits) {
879                 /* Clear the errors.  */
880                 schizo_write(csr_reg, csr);
881
882                 /* Log 'em.  */
883                 if (csr_error_bits & SCHIZO_PCICTRL_BUS_UNUS)
884                         printk("%s: Bus unusable error asserted.\n",
885                                pbm->name);
886                 if (csr_error_bits & SCHIZO_PCICTRL_TTO_ERR)
887                         printk("%s: PCI TRDY# timeout error asserted.\n",
888                                pbm->name);
889                 if (csr_error_bits & SCHIZO_PCICTRL_RTRY_ERR)
890                         printk("%s: PCI excessive retry error asserted.\n",
891                                pbm->name);
892                 if (csr_error_bits & SCHIZO_PCICTRL_DTO_ERR)
893                         printk("%s: PCI discard timeout error asserted.\n",
894                                pbm->name);
895                 if (csr_error_bits & SCHIZO_PCICTRL_SBH_ERR)
896                         printk("%s: PCI streaming byte hole error asserted.\n",
897                                pbm->name);
898                 if (csr_error_bits & SCHIZO_PCICTRL_SERR)
899                         printk("%s: PCI SERR signal asserted.\n",
900                                pbm->name);
901                 ret = IRQ_HANDLED;
902         }
903         pci_read_config_word(pbm->pci_bus->self, PCI_STATUS, &stat);
904         if (stat & (PCI_STATUS_PARITY |
905                     PCI_STATUS_SIG_TARGET_ABORT |
906                     PCI_STATUS_REC_TARGET_ABORT |
907                     PCI_STATUS_REC_MASTER_ABORT |
908                     PCI_STATUS_SIG_SYSTEM_ERROR)) {
909                 printk("%s: PCI bus error, PCI_STATUS[%04x]\n",
910                        pbm->name, stat);
911                 pci_write_config_word(pbm->pci_bus->self, PCI_STATUS, 0xffff);
912                 ret = IRQ_HANDLED;
913         }
914         return ret;
915 }
916
917 static irqreturn_t schizo_pcierr_intr(int irq, void *dev_id, struct pt_regs *regs)
918 {
919         struct pci_pbm_info *pbm = dev_id;
920         struct pci_controller_info *p = pbm->parent;
921         unsigned long afsr_reg, afar_reg, base;
922         unsigned long afsr, afar, error_bits;
923         int reported;
924
925         base = pbm->pbm_regs;
926
927         afsr_reg = base + SCHIZO_PCI_AFSR;
928         afar_reg = base + SCHIZO_PCI_AFAR;
929
930         /* Latch error status. */
931         afar = schizo_read(afar_reg);
932         afsr = schizo_read(afsr_reg);
933
934         /* Clear primary/secondary error status bits. */
935         error_bits = afsr &
936                 (SCHIZO_PCIAFSR_PMA | SCHIZO_PCIAFSR_PTA |
937                  SCHIZO_PCIAFSR_PRTRY | SCHIZO_PCIAFSR_PPERR |
938                  SCHIZO_PCIAFSR_PTTO | SCHIZO_PCIAFSR_PUNUS |
939                  SCHIZO_PCIAFSR_SMA | SCHIZO_PCIAFSR_STA |
940                  SCHIZO_PCIAFSR_SRTRY | SCHIZO_PCIAFSR_SPERR |
941                  SCHIZO_PCIAFSR_STTO | SCHIZO_PCIAFSR_SUNUS);
942         if (!error_bits)
943                 return schizo_pcierr_intr_other(pbm);
944         schizo_write(afsr_reg, error_bits);
945
946         /* Log the error. */
947         printk("%s: PCI Error, primary error type[%s]\n",
948                pbm->name,
949                (((error_bits & SCHIZO_PCIAFSR_PMA) ?
950                  "Master Abort" :
951                  ((error_bits & SCHIZO_PCIAFSR_PTA) ?
952                   "Target Abort" :
953                   ((error_bits & SCHIZO_PCIAFSR_PRTRY) ?
954                    "Excessive Retries" :
955                    ((error_bits & SCHIZO_PCIAFSR_PPERR) ?
956                     "Parity Error" :
957                     ((error_bits & SCHIZO_PCIAFSR_PTTO) ?
958                      "Timeout" :
959                      ((error_bits & SCHIZO_PCIAFSR_PUNUS) ?
960                       "Bus Unusable" : "???"))))))));
961         printk("%s: bytemask[%04lx] was_block(%d) space(%s)\n",
962                pbm->name,
963                (afsr & SCHIZO_PCIAFSR_BMSK) >> 32UL,
964                (afsr & SCHIZO_PCIAFSR_BLK) ? 1 : 0,
965                ((afsr & SCHIZO_PCIAFSR_CFG) ?
966                 "Config" :
967                 ((afsr & SCHIZO_PCIAFSR_MEM) ?
968                  "Memory" :
969                  ((afsr & SCHIZO_PCIAFSR_IO) ?
970                   "I/O" : "???"))));
971         printk("%s: PCI AFAR [%016lx]\n",
972                pbm->name, afar);
973         printk("%s: PCI Secondary errors [",
974                pbm->name);
975         reported = 0;
976         if (afsr & SCHIZO_PCIAFSR_SMA) {
977                 reported++;
978                 printk("(Master Abort)");
979         }
980         if (afsr & SCHIZO_PCIAFSR_STA) {
981                 reported++;
982                 printk("(Target Abort)");
983         }
984         if (afsr & SCHIZO_PCIAFSR_SRTRY) {
985                 reported++;
986                 printk("(Excessive Retries)");
987         }
988         if (afsr & SCHIZO_PCIAFSR_SPERR) {
989                 reported++;
990                 printk("(Parity Error)");
991         }
992         if (afsr & SCHIZO_PCIAFSR_STTO) {
993                 reported++;
994                 printk("(Timeout)");
995         }
996         if (afsr & SCHIZO_PCIAFSR_SUNUS) {
997                 reported++;
998                 printk("(Bus Unusable)");
999         }
1000         if (!reported)
1001                 printk("(none)");
1002         printk("]\n");
1003
1004         /* For the error types shown, scan PBM's PCI bus for devices
1005          * which have logged that error type.
1006          */
1007
1008         /* If we see a Target Abort, this could be the result of an
1009          * IOMMU translation error of some sort.  It is extremely
1010          * useful to log this information as usually it indicates
1011          * a bug in the IOMMU support code or a PCI device driver.
1012          */
1013         if (error_bits & (SCHIZO_PCIAFSR_PTA | SCHIZO_PCIAFSR_STA)) {
1014                 schizo_check_iommu_error(p, PCI_ERR);
1015                 pci_scan_for_target_abort(p, pbm, pbm->pci_bus);
1016         }
1017         if (error_bits & (SCHIZO_PCIAFSR_PMA | SCHIZO_PCIAFSR_SMA))
1018                 pci_scan_for_master_abort(p, pbm, pbm->pci_bus);
1019
1020         /* For excessive retries, PSYCHO/PBM will abort the device
1021          * and there is no way to specifically check for excessive
1022          * retries in the config space status registers.  So what
1023          * we hope is that we'll catch it via the master/target
1024          * abort events.
1025          */
1026
1027         if (error_bits & (SCHIZO_PCIAFSR_PPERR | SCHIZO_PCIAFSR_SPERR))
1028                 pci_scan_for_parity_error(p, pbm, pbm->pci_bus);
1029
1030         schizo_clear_other_err_intr(p, irq);
1031
1032         return IRQ_HANDLED;
1033 }
1034
1035 #define SCHIZO_SAFARI_ERRLOG    0x10018UL
1036
1037 #define SAFARI_ERRLOG_ERROUT    0x8000000000000000UL
1038
1039 #define BUS_ERROR_BADCMD        0x4000000000000000UL /* Schizo/Tomatillo */
1040 #define BUS_ERROR_SSMDIS        0x2000000000000000UL /* Safari */
1041 #define BUS_ERROR_BADMA         0x1000000000000000UL /* Safari */
1042 #define BUS_ERROR_BADMB         0x0800000000000000UL /* Safari */
1043 #define BUS_ERROR_BADMC         0x0400000000000000UL /* Safari */
1044 #define BUS_ERROR_SNOOP_GR      0x0000000000200000UL /* Tomatillo */
1045 #define BUS_ERROR_SNOOP_PCI     0x0000000000100000UL /* Tomatillo */
1046 #define BUS_ERROR_SNOOP_RD      0x0000000000080000UL /* Tomatillo */
1047 #define BUS_ERROR_SNOOP_RDS     0x0000000000020000UL /* Tomatillo */
1048 #define BUS_ERROR_SNOOP_RDSA    0x0000000000010000UL /* Tomatillo */
1049 #define BUS_ERROR_SNOOP_OWN     0x0000000000008000UL /* Tomatillo */
1050 #define BUS_ERROR_SNOOP_RDO     0x0000000000004000UL /* Tomatillo */
1051 #define BUS_ERROR_CPU1PS        0x0000000000002000UL /* Safari */
1052 #define BUS_ERROR_WDATA_PERR    0x0000000000002000UL /* Tomatillo */
1053 #define BUS_ERROR_CPU1PB        0x0000000000001000UL /* Safari */
1054 #define BUS_ERROR_CTRL_PERR     0x0000000000001000UL /* Tomatillo */
1055 #define BUS_ERROR_CPU0PS        0x0000000000000800UL /* Safari */
1056 #define BUS_ERROR_SNOOP_ERR     0x0000000000000800UL /* Tomatillo */
1057 #define BUS_ERROR_CPU0PB        0x0000000000000400UL /* Safari */
1058 #define BUS_ERROR_JBUS_ILL_B    0x0000000000000400UL /* Tomatillo */
1059 #define BUS_ERROR_CIQTO         0x0000000000000200UL /* Safari */
1060 #define BUS_ERROR_LPQTO         0x0000000000000100UL /* Safari */
1061 #define BUS_ERROR_JBUS_ILL_C    0x0000000000000100UL /* Tomatillo */
1062 #define BUS_ERROR_SFPQTO        0x0000000000000080UL /* Safari */
1063 #define BUS_ERROR_UFPQTO        0x0000000000000040UL /* Safari */
1064 #define BUS_ERROR_RD_PERR       0x0000000000000040UL /* Tomatillo */
1065 #define BUS_ERROR_APERR         0x0000000000000020UL /* Safari/Tomatillo */
1066 #define BUS_ERROR_UNMAP         0x0000000000000010UL /* Safari/Tomatillo */
1067 #define BUS_ERROR_BUSERR        0x0000000000000004UL /* Safari/Tomatillo */
1068 #define BUS_ERROR_TIMEOUT       0x0000000000000002UL /* Safari/Tomatillo */
1069 #define BUS_ERROR_ILL           0x0000000000000001UL /* Safari */
1070
1071 /* We only expect UNMAP errors here.  The rest of the Safari errors
1072  * are marked fatal and thus cause a system reset.
1073  */
1074 static irqreturn_t schizo_safarierr_intr(int irq, void *dev_id, struct pt_regs *regs)
1075 {
1076         struct pci_controller_info *p = dev_id;
1077         u64 errlog;
1078
1079         errlog = schizo_read(p->pbm_B.controller_regs + SCHIZO_SAFARI_ERRLOG);
1080         schizo_write(p->pbm_B.controller_regs + SCHIZO_SAFARI_ERRLOG,
1081                      errlog & ~(SAFARI_ERRLOG_ERROUT));
1082
1083         if (!(errlog & BUS_ERROR_UNMAP)) {
1084                 printk("PCI%d: Unexpected Safari/JBUS error interrupt, errlog[%016lx]\n",
1085                        p->index, errlog);
1086
1087                 schizo_clear_other_err_intr(p, irq);
1088                 return IRQ_HANDLED;
1089         }
1090
1091         printk("PCI%d: Safari/JBUS interrupt, UNMAPPED error, interrogating IOMMUs.\n",
1092                p->index);
1093         schizo_check_iommu_error(p, SAFARI_ERR);
1094
1095         schizo_clear_other_err_intr(p, irq);
1096         return IRQ_HANDLED;
1097 }
1098
1099 /* Nearly identical to PSYCHO equivalents... */
1100 #define SCHIZO_ECC_CTRL         0x10020UL
1101 #define  SCHIZO_ECCCTRL_EE       0x8000000000000000UL /* Enable ECC Checking */
1102 #define  SCHIZO_ECCCTRL_UE       0x4000000000000000UL /* Enable UE Interrupts */
1103 #define  SCHIZO_ECCCTRL_CE       0x2000000000000000UL /* Enable CE INterrupts */
1104
1105 #define SCHIZO_SAFARI_ERRCTRL   0x10008UL
1106 #define  SCHIZO_SAFERRCTRL_EN    0x8000000000000000UL
1107 #define SCHIZO_SAFARI_IRQCTRL   0x10010UL
1108 #define  SCHIZO_SAFIRQCTRL_EN    0x8000000000000000UL
1109
1110 /* How the Tomatillo IRQs are routed around is pure guesswork here.
1111  *
1112  * All the Tomatillo devices I see in prtconf dumps seem to have only
1113  * a single PCI bus unit attached to it.  It would seem they are seperate
1114  * devices because their PortID (ie. JBUS ID) values are all different
1115  * and thus the registers are mapped to totally different locations.
1116  *
1117  * However, two Tomatillo's look "similar" in that the only difference
1118  * in their PortID is the lowest bit.
1119  *
1120  * So if we were to ignore this lower bit, it certainly looks like two
1121  * PCI bus units of the same Tomatillo.  I still have not really
1122  * figured this out...
1123  */
1124 static void tomatillo_register_error_handlers(struct pci_controller_info *p)
1125 {
1126         struct pci_pbm_info *pbm;
1127         unsigned int irq;
1128         struct ino_bucket *bucket;
1129         u64 tmp, err_mask, err_no_mask;
1130
1131         /* Build IRQs and register handlers. */
1132         pbm = pbm_for_ino(p, SCHIZO_UE_INO);
1133         irq = schizo_irq_build(pbm, NULL, (pbm->portid << 6) | SCHIZO_UE_INO);
1134         if (request_irq(irq, schizo_ue_intr,
1135                         SA_SHIRQ, "TOMATILLO UE", p) < 0) {
1136                 prom_printf("%s: Cannot register UE interrupt.\n",
1137                             pbm->name);
1138                 prom_halt();
1139         }
1140         bucket = __bucket(irq);
1141         tmp = upa_readl(bucket->imap);
1142         upa_writel(tmp, (pbm->pbm_regs +
1143                          schizo_imap_offset(SCHIZO_UE_INO) + 4));
1144
1145         pbm = pbm_for_ino(p, SCHIZO_CE_INO);
1146         irq = schizo_irq_build(pbm, NULL, (pbm->portid << 6) | SCHIZO_CE_INO);
1147         if (request_irq(irq, schizo_ce_intr,
1148                         SA_SHIRQ, "TOMATILLO CE", p) < 0) {
1149                 prom_printf("%s: Cannot register CE interrupt.\n",
1150                             pbm->name);
1151                 prom_halt();
1152         }
1153         bucket = __bucket(irq);
1154         tmp = upa_readl(bucket->imap);
1155         upa_writel(tmp, (pbm->pbm_regs +
1156                          schizo_imap_offset(SCHIZO_CE_INO) + 4));
1157
1158         pbm = pbm_for_ino(p, SCHIZO_PCIERR_A_INO);
1159         irq = schizo_irq_build(pbm, NULL, ((pbm->portid << 6) |
1160                                            SCHIZO_PCIERR_A_INO));
1161         if (request_irq(irq, schizo_pcierr_intr,
1162                         SA_SHIRQ, "TOMATILLO PCIERR", pbm) < 0) {
1163                 prom_printf("%s: Cannot register PBM A PciERR interrupt.\n",
1164                             pbm->name);
1165                 prom_halt();
1166         }
1167         bucket = __bucket(irq);
1168         tmp = upa_readl(bucket->imap);
1169         upa_writel(tmp, (pbm->pbm_regs +
1170                          schizo_imap_offset(SCHIZO_PCIERR_A_INO) + 4));
1171
1172         pbm = pbm_for_ino(p, SCHIZO_PCIERR_B_INO);
1173         irq = schizo_irq_build(pbm, NULL, ((pbm->portid << 6) |
1174                                             SCHIZO_PCIERR_B_INO));
1175         if (request_irq(irq, schizo_pcierr_intr,
1176                         SA_SHIRQ, "TOMATILLO PCIERR", pbm) < 0) {
1177                 prom_printf("%s: Cannot register PBM B PciERR interrupt.\n",
1178                             pbm->name);
1179                 prom_halt();
1180         }
1181         bucket = __bucket(irq);
1182         tmp = upa_readl(bucket->imap);
1183         upa_writel(tmp, (pbm->pbm_regs +
1184                          schizo_imap_offset(SCHIZO_PCIERR_B_INO) + 4));
1185
1186         pbm = pbm_for_ino(p, SCHIZO_SERR_INO);
1187         irq = schizo_irq_build(pbm, NULL, (pbm->portid << 6) | SCHIZO_SERR_INO);
1188         if (request_irq(irq, schizo_safarierr_intr,
1189                         SA_SHIRQ, "TOMATILLO SERR", p) < 0) {
1190                 prom_printf("%s: Cannot register SafariERR interrupt.\n",
1191                             pbm->name);
1192                 prom_halt();
1193         }
1194         bucket = __bucket(irq);
1195         tmp = upa_readl(bucket->imap);
1196         upa_writel(tmp, (pbm->pbm_regs +
1197                          schizo_imap_offset(SCHIZO_SERR_INO) + 4));
1198
1199         /* Enable UE and CE interrupts for controller. */
1200         schizo_write(p->pbm_A.controller_regs + SCHIZO_ECC_CTRL,
1201                      (SCHIZO_ECCCTRL_EE |
1202                       SCHIZO_ECCCTRL_UE |
1203                       SCHIZO_ECCCTRL_CE));
1204
1205         schizo_write(p->pbm_B.controller_regs + SCHIZO_ECC_CTRL,
1206                      (SCHIZO_ECCCTRL_EE |
1207                       SCHIZO_ECCCTRL_UE |
1208                       SCHIZO_ECCCTRL_CE));
1209
1210         /* Enable PCI Error interrupts and clear error
1211          * bits.
1212          */
1213         err_mask = (SCHIZO_PCICTRL_BUS_UNUS |
1214                     SCHIZO_PCICTRL_TTO_ERR |
1215                     SCHIZO_PCICTRL_RTRY_ERR |
1216                     SCHIZO_PCICTRL_SERR |
1217                     SCHIZO_PCICTRL_EEN);
1218
1219         err_no_mask = SCHIZO_PCICTRL_DTO_ERR;
1220
1221         tmp = schizo_read(p->pbm_A.pbm_regs + SCHIZO_PCI_CTRL);
1222         tmp |= err_mask;
1223         tmp &= ~err_no_mask;
1224         schizo_write(p->pbm_A.pbm_regs + SCHIZO_PCI_CTRL, tmp);
1225
1226         tmp = schizo_read(p->pbm_B.pbm_regs + SCHIZO_PCI_CTRL);
1227         tmp |= err_mask;
1228         tmp &= ~err_no_mask;
1229         schizo_write(p->pbm_B.pbm_regs + SCHIZO_PCI_CTRL, tmp);
1230
1231         err_mask = (SCHIZO_PCIAFSR_PMA | SCHIZO_PCIAFSR_PTA |
1232                     SCHIZO_PCIAFSR_PRTRY | SCHIZO_PCIAFSR_PPERR |
1233                     SCHIZO_PCIAFSR_PTTO |
1234                     SCHIZO_PCIAFSR_SMA | SCHIZO_PCIAFSR_STA |
1235                     SCHIZO_PCIAFSR_SRTRY | SCHIZO_PCIAFSR_SPERR |
1236                     SCHIZO_PCIAFSR_STTO);
1237
1238         schizo_write(p->pbm_A.pbm_regs + SCHIZO_PCI_AFSR, err_mask);
1239         schizo_write(p->pbm_B.pbm_regs + SCHIZO_PCI_AFSR, err_mask);
1240
1241         err_mask = (BUS_ERROR_BADCMD | BUS_ERROR_SNOOP_GR |
1242                     BUS_ERROR_SNOOP_PCI | BUS_ERROR_SNOOP_RD |
1243                     BUS_ERROR_SNOOP_RDS | BUS_ERROR_SNOOP_RDSA |
1244                     BUS_ERROR_SNOOP_OWN | BUS_ERROR_SNOOP_RDO |
1245                     BUS_ERROR_WDATA_PERR | BUS_ERROR_CTRL_PERR |
1246                     BUS_ERROR_SNOOP_ERR | BUS_ERROR_JBUS_ILL_B |
1247                     BUS_ERROR_JBUS_ILL_C | BUS_ERROR_RD_PERR |
1248                     BUS_ERROR_APERR | BUS_ERROR_UNMAP |
1249                     BUS_ERROR_BUSERR | BUS_ERROR_TIMEOUT);
1250
1251         schizo_write(p->pbm_A.controller_regs + SCHIZO_SAFARI_ERRCTRL,
1252                      (SCHIZO_SAFERRCTRL_EN | err_mask));
1253         schizo_write(p->pbm_B.controller_regs + SCHIZO_SAFARI_ERRCTRL,
1254                      (SCHIZO_SAFERRCTRL_EN | err_mask));
1255
1256         schizo_write(p->pbm_A.controller_regs + SCHIZO_SAFARI_IRQCTRL,
1257                      (SCHIZO_SAFIRQCTRL_EN | (BUS_ERROR_UNMAP)));
1258         schizo_write(p->pbm_B.controller_regs + SCHIZO_SAFARI_IRQCTRL,
1259                      (SCHIZO_SAFIRQCTRL_EN | (BUS_ERROR_UNMAP)));
1260 }
1261
1262 static void schizo_register_error_handlers(struct pci_controller_info *p)
1263 {
1264         struct pci_pbm_info *pbm;
1265         unsigned int irq;
1266         struct ino_bucket *bucket;
1267         u64 tmp, err_mask, err_no_mask;
1268
1269         /* Build IRQs and register handlers. */
1270         pbm = pbm_for_ino(p, SCHIZO_UE_INO);
1271         irq = schizo_irq_build(pbm, NULL, (pbm->portid << 6) | SCHIZO_UE_INO);
1272         if (request_irq(irq, schizo_ue_intr,
1273                         SA_SHIRQ, "SCHIZO UE", p) < 0) {
1274                 prom_printf("%s: Cannot register UE interrupt.\n",
1275                             pbm->name);
1276                 prom_halt();
1277         }
1278         bucket = __bucket(irq);
1279         tmp = upa_readl(bucket->imap);
1280         upa_writel(tmp, (pbm->pbm_regs + schizo_imap_offset(SCHIZO_UE_INO) + 4));
1281
1282         pbm = pbm_for_ino(p, SCHIZO_CE_INO);
1283         irq = schizo_irq_build(pbm, NULL, (pbm->portid << 6) | SCHIZO_CE_INO);
1284         if (request_irq(irq, schizo_ce_intr,
1285                         SA_SHIRQ, "SCHIZO CE", p) < 0) {
1286                 prom_printf("%s: Cannot register CE interrupt.\n",
1287                             pbm->name);
1288                 prom_halt();
1289         }
1290         bucket = __bucket(irq);
1291         tmp = upa_readl(bucket->imap);
1292         upa_writel(tmp, (pbm->pbm_regs + schizo_imap_offset(SCHIZO_CE_INO) + 4));
1293
1294         pbm = pbm_for_ino(p, SCHIZO_PCIERR_A_INO);
1295         irq = schizo_irq_build(pbm, NULL, (pbm->portid << 6) | SCHIZO_PCIERR_A_INO);
1296         if (request_irq(irq, schizo_pcierr_intr,
1297                         SA_SHIRQ, "SCHIZO PCIERR", pbm) < 0) {
1298                 prom_printf("%s: Cannot register PBM A PciERR interrupt.\n",
1299                             pbm->name);
1300                 prom_halt();
1301         }
1302         bucket = __bucket(irq);
1303         tmp = upa_readl(bucket->imap);
1304         upa_writel(tmp, (pbm->pbm_regs + schizo_imap_offset(SCHIZO_PCIERR_A_INO) + 4));
1305
1306         pbm = pbm_for_ino(p, SCHIZO_PCIERR_B_INO);
1307         irq = schizo_irq_build(pbm, NULL, (pbm->portid << 6) | SCHIZO_PCIERR_B_INO);
1308         if (request_irq(irq, schizo_pcierr_intr,
1309                         SA_SHIRQ, "SCHIZO PCIERR", &p->pbm_B) < 0) {
1310                 prom_printf("%s: Cannot register PBM B PciERR interrupt.\n",
1311                             pbm->name);
1312                 prom_halt();
1313         }
1314         bucket = __bucket(irq);
1315         tmp = upa_readl(bucket->imap);
1316         upa_writel(tmp, (pbm->pbm_regs + schizo_imap_offset(SCHIZO_PCIERR_B_INO) + 4));
1317
1318         pbm = pbm_for_ino(p, SCHIZO_SERR_INO);
1319         irq = schizo_irq_build(pbm, NULL, (pbm->portid << 6) | SCHIZO_SERR_INO);
1320         if (request_irq(irq, schizo_safarierr_intr,
1321                         SA_SHIRQ, "SCHIZO SERR", p) < 0) {
1322                 prom_printf("%s: Cannot register SafariERR interrupt.\n",
1323                             pbm->name);
1324                 prom_halt();
1325         }
1326         bucket = __bucket(irq);
1327         tmp = upa_readl(bucket->imap);
1328         upa_writel(tmp, (pbm->pbm_regs + schizo_imap_offset(SCHIZO_SERR_INO) + 4));
1329
1330         /* Enable UE and CE interrupts for controller. */
1331         schizo_write(p->pbm_A.controller_regs + SCHIZO_ECC_CTRL,
1332                      (SCHIZO_ECCCTRL_EE |
1333                       SCHIZO_ECCCTRL_UE |
1334                       SCHIZO_ECCCTRL_CE));
1335
1336         err_mask = (SCHIZO_PCICTRL_BUS_UNUS |
1337                     SCHIZO_PCICTRL_ESLCK |
1338                     SCHIZO_PCICTRL_TTO_ERR |
1339                     SCHIZO_PCICTRL_RTRY_ERR |
1340                     SCHIZO_PCICTRL_SBH_ERR |
1341                     SCHIZO_PCICTRL_SERR |
1342                     SCHIZO_PCICTRL_EEN);
1343
1344         err_no_mask = (SCHIZO_PCICTRL_DTO_ERR |
1345                        SCHIZO_PCICTRL_SBH_INT);
1346
1347         /* Enable PCI Error interrupts and clear error
1348          * bits for each PBM.
1349          */
1350         tmp = schizo_read(p->pbm_A.pbm_regs + SCHIZO_PCI_CTRL);
1351         tmp |= err_mask;
1352         tmp &= ~err_no_mask;
1353         schizo_write(p->pbm_A.pbm_regs + SCHIZO_PCI_CTRL, tmp);
1354
1355         schizo_write(p->pbm_A.pbm_regs + SCHIZO_PCI_AFSR,
1356                      (SCHIZO_PCIAFSR_PMA | SCHIZO_PCIAFSR_PTA |
1357                       SCHIZO_PCIAFSR_PRTRY | SCHIZO_PCIAFSR_PPERR |
1358                       SCHIZO_PCIAFSR_PTTO | SCHIZO_PCIAFSR_PUNUS |
1359                       SCHIZO_PCIAFSR_SMA | SCHIZO_PCIAFSR_STA |
1360                       SCHIZO_PCIAFSR_SRTRY | SCHIZO_PCIAFSR_SPERR |
1361                       SCHIZO_PCIAFSR_STTO | SCHIZO_PCIAFSR_SUNUS));
1362
1363         tmp = schizo_read(p->pbm_B.pbm_regs + SCHIZO_PCI_CTRL);
1364         tmp |= err_mask;
1365         tmp &= ~err_no_mask;
1366         schizo_write(p->pbm_B.pbm_regs + SCHIZO_PCI_CTRL, tmp);
1367
1368         schizo_write(p->pbm_B.pbm_regs + SCHIZO_PCI_AFSR,
1369                      (SCHIZO_PCIAFSR_PMA | SCHIZO_PCIAFSR_PTA |
1370                       SCHIZO_PCIAFSR_PRTRY | SCHIZO_PCIAFSR_PPERR |
1371                       SCHIZO_PCIAFSR_PTTO | SCHIZO_PCIAFSR_PUNUS |
1372                       SCHIZO_PCIAFSR_SMA | SCHIZO_PCIAFSR_STA |
1373                       SCHIZO_PCIAFSR_SRTRY | SCHIZO_PCIAFSR_SPERR |
1374                       SCHIZO_PCIAFSR_STTO | SCHIZO_PCIAFSR_SUNUS));
1375
1376         /* Make all Safari error conditions fatal except unmapped
1377          * errors which we make generate interrupts.
1378          */
1379         err_mask = (BUS_ERROR_BADCMD | BUS_ERROR_SSMDIS |
1380                     BUS_ERROR_BADMA | BUS_ERROR_BADMB |
1381                     BUS_ERROR_BADMC |
1382                     BUS_ERROR_CPU1PS | BUS_ERROR_CPU1PB |
1383                     BUS_ERROR_CPU0PS | BUS_ERROR_CPU0PB |
1384                     BUS_ERROR_CIQTO |
1385                     BUS_ERROR_LPQTO | BUS_ERROR_SFPQTO |
1386                     BUS_ERROR_UFPQTO | BUS_ERROR_APERR |
1387                     BUS_ERROR_BUSERR | BUS_ERROR_TIMEOUT |
1388                     BUS_ERROR_ILL);
1389 #if 1
1390         /* XXX Something wrong with some Excalibur systems
1391          * XXX Sun is shipping.  The behavior on a 2-cpu
1392          * XXX machine is that both CPU1 parity error bits
1393          * XXX are set and are immediately set again when
1394          * XXX their error status bits are cleared.  Just
1395          * XXX ignore them for now.  -DaveM
1396          */
1397         err_mask &= ~(BUS_ERROR_CPU1PS | BUS_ERROR_CPU1PB |
1398                       BUS_ERROR_CPU0PS | BUS_ERROR_CPU0PB);
1399 #endif
1400
1401         schizo_write(p->pbm_A.controller_regs + SCHIZO_SAFARI_ERRCTRL,
1402                      (SCHIZO_SAFERRCTRL_EN | err_mask));
1403
1404         schizo_write(p->pbm_A.controller_regs + SCHIZO_SAFARI_IRQCTRL,
1405                      (SCHIZO_SAFIRQCTRL_EN | (BUS_ERROR_UNMAP)));
1406 }
1407
1408 static void pbm_config_busmastering(struct pci_pbm_info *pbm)
1409 {
1410         u8 *addr;
1411
1412         /* Set cache-line size to 64 bytes, this is actually
1413          * a nop but I do it for completeness.
1414          */
1415         addr = schizo_pci_config_mkaddr(pbm, pbm->pci_first_busno,
1416                                         0, PCI_CACHE_LINE_SIZE);
1417         pci_config_write8(addr, 64 / sizeof(u32));
1418
1419         /* Set PBM latency timer to 64 PCI clocks. */
1420         addr = schizo_pci_config_mkaddr(pbm, pbm->pci_first_busno,
1421                                         0, PCI_LATENCY_TIMER);
1422         pci_config_write8(addr, 64);
1423 }
1424
1425 static void pbm_scan_bus(struct pci_controller_info *p,
1426                          struct pci_pbm_info *pbm)
1427 {
1428         struct pcidev_cookie *cookie = kzalloc(sizeof(*cookie), GFP_KERNEL);
1429
1430         if (!cookie) {
1431                 prom_printf("%s: Critical allocation failure.\n", pbm->name);
1432                 prom_halt();
1433         }
1434
1435         /* All we care about is the PBM. */
1436         cookie->pbm = pbm;
1437
1438         pbm->pci_bus = pci_scan_bus(pbm->pci_first_busno,
1439                                     p->pci_ops,
1440                                     pbm);
1441         pci_fixup_host_bridge_self(pbm->pci_bus);
1442         pbm->pci_bus->self->sysdata = cookie;
1443
1444         pci_fill_in_pbm_cookies(pbm->pci_bus, pbm, pbm->prom_node);
1445         pci_record_assignments(pbm, pbm->pci_bus);
1446         pci_assign_unassigned(pbm, pbm->pci_bus);
1447         pci_fixup_irq(pbm, pbm->pci_bus);
1448         pci_determine_66mhz_disposition(pbm, pbm->pci_bus);
1449         pci_setup_busmastering(pbm, pbm->pci_bus);
1450 }
1451
1452 static void __schizo_scan_bus(struct pci_controller_info *p,
1453                               int chip_type)
1454 {
1455         if (!p->pbm_B.prom_node || !p->pbm_A.prom_node) {
1456                 printk("PCI: Only one PCI bus module of controller found.\n");
1457                 printk("PCI: Ignoring entire controller.\n");
1458                 return;
1459         }
1460
1461         pbm_config_busmastering(&p->pbm_B);
1462         p->pbm_B.is_66mhz_capable =
1463                 prom_getbool(p->pbm_B.prom_node, "66mhz-capable");
1464         pbm_config_busmastering(&p->pbm_A);
1465         p->pbm_A.is_66mhz_capable =
1466                 prom_getbool(p->pbm_A.prom_node, "66mhz-capable");
1467         pbm_scan_bus(p, &p->pbm_B);
1468         pbm_scan_bus(p, &p->pbm_A);
1469
1470         /* After the PCI bus scan is complete, we can register
1471          * the error interrupt handlers.
1472          */
1473         if (chip_type == PBM_CHIP_TYPE_TOMATILLO)
1474                 tomatillo_register_error_handlers(p);
1475         else
1476                 schizo_register_error_handlers(p);
1477 }
1478
1479 static void schizo_scan_bus(struct pci_controller_info *p)
1480 {
1481         __schizo_scan_bus(p, PBM_CHIP_TYPE_SCHIZO);
1482 }
1483
1484 static void tomatillo_scan_bus(struct pci_controller_info *p)
1485 {
1486         __schizo_scan_bus(p, PBM_CHIP_TYPE_TOMATILLO);
1487 }
1488
1489 static void schizo_base_address_update(struct pci_dev *pdev, int resource)
1490 {
1491         struct pcidev_cookie *pcp = pdev->sysdata;
1492         struct pci_pbm_info *pbm = pcp->pbm;
1493         struct resource *res, *root;
1494         u32 reg;
1495         int where, size, is_64bit;
1496
1497         res = &pdev->resource[resource];
1498         if (resource < 6) {
1499                 where = PCI_BASE_ADDRESS_0 + (resource * 4);
1500         } else if (resource == PCI_ROM_RESOURCE) {
1501                 where = pdev->rom_base_reg;
1502         } else {
1503                 /* Somebody might have asked allocation of a non-standard resource */
1504                 return;
1505         }
1506
1507         is_64bit = 0;
1508         if (res->flags & IORESOURCE_IO)
1509                 root = &pbm->io_space;
1510         else {
1511                 root = &pbm->mem_space;
1512                 if ((res->flags & PCI_BASE_ADDRESS_MEM_TYPE_MASK)
1513                     == PCI_BASE_ADDRESS_MEM_TYPE_64)
1514                         is_64bit = 1;
1515         }
1516
1517         size = res->end - res->start;
1518         pci_read_config_dword(pdev, where, &reg);
1519         reg = ((reg & size) |
1520                (((u32)(res->start - root->start)) & ~size));
1521         if (resource == PCI_ROM_RESOURCE) {
1522                 reg |= PCI_ROM_ADDRESS_ENABLE;
1523                 res->flags |= IORESOURCE_ROM_ENABLE;
1524         }
1525         pci_write_config_dword(pdev, where, reg);
1526
1527         /* This knows that the upper 32-bits of the address
1528          * must be zero.  Our PCI common layer enforces this.
1529          */
1530         if (is_64bit)
1531                 pci_write_config_dword(pdev, where + 4, 0);
1532 }
1533
1534 static void schizo_resource_adjust(struct pci_dev *pdev,
1535                                    struct resource *res,
1536                                    struct resource *root)
1537 {
1538         res->start += root->start;
1539         res->end += root->start;
1540 }
1541
1542 /* Use ranges property to determine where PCI MEM, I/O, and Config
1543  * space are for this PCI bus module.
1544  */
1545 static void schizo_determine_mem_io_space(struct pci_pbm_info *pbm)
1546 {
1547         int i, saw_cfg, saw_mem, saw_io;
1548
1549         saw_cfg = saw_mem = saw_io = 0;
1550         for (i = 0; i < pbm->num_pbm_ranges; i++) {
1551                 struct linux_prom_pci_ranges *pr = &pbm->pbm_ranges[i];
1552                 unsigned long a;
1553                 int type;
1554
1555                 type = (pr->child_phys_hi >> 24) & 0x3;
1556                 a = (((unsigned long)pr->parent_phys_hi << 32UL) |
1557                      ((unsigned long)pr->parent_phys_lo  <<  0UL));
1558
1559                 switch (type) {
1560                 case 0:
1561                         /* PCI config space, 16MB */
1562                         pbm->config_space = a;
1563                         saw_cfg = 1;
1564                         break;
1565
1566                 case 1:
1567                         /* 16-bit IO space, 16MB */
1568                         pbm->io_space.start = a;
1569                         pbm->io_space.end = a + ((16UL*1024UL*1024UL) - 1UL);
1570                         pbm->io_space.flags = IORESOURCE_IO;
1571                         saw_io = 1;
1572                         break;
1573
1574                 case 2:
1575                         /* 32-bit MEM space, 2GB */
1576                         pbm->mem_space.start = a;
1577                         pbm->mem_space.end = a + (0x80000000UL - 1UL);
1578                         pbm->mem_space.flags = IORESOURCE_MEM;
1579                         saw_mem = 1;
1580                         break;
1581
1582                 default:
1583                         break;
1584                 };
1585         }
1586
1587         if (!saw_cfg || !saw_io || !saw_mem) {
1588                 prom_printf("%s: Fatal error, missing %s PBM range.\n",
1589                             pbm->name,
1590                             ((!saw_cfg ?
1591                               "CFG" :
1592                               (!saw_io ?
1593                                "IO" : "MEM"))));
1594                 prom_halt();
1595         }
1596
1597         printk("%s: PCI CFG[%lx] IO[%lx] MEM[%lx]\n",
1598                pbm->name,
1599                pbm->config_space,
1600                pbm->io_space.start,
1601                pbm->mem_space.start);
1602 }
1603
1604 static void pbm_register_toplevel_resources(struct pci_controller_info *p,
1605                                             struct pci_pbm_info *pbm)
1606 {
1607         pbm->io_space.name = pbm->mem_space.name = pbm->name;
1608
1609         request_resource(&ioport_resource, &pbm->io_space);
1610         request_resource(&iomem_resource, &pbm->mem_space);
1611         pci_register_legacy_regions(&pbm->io_space,
1612                                     &pbm->mem_space);
1613 }
1614
1615 #define SCHIZO_STRBUF_CONTROL           (0x02800UL)
1616 #define SCHIZO_STRBUF_FLUSH             (0x02808UL)
1617 #define SCHIZO_STRBUF_FSYNC             (0x02810UL)
1618 #define SCHIZO_STRBUF_CTXFLUSH          (0x02818UL)
1619 #define SCHIZO_STRBUF_CTXMATCH          (0x10000UL)
1620
1621 static void schizo_pbm_strbuf_init(struct pci_pbm_info *pbm)
1622 {
1623         unsigned long base = pbm->pbm_regs;
1624         u64 control;
1625
1626         if (pbm->chip_type == PBM_CHIP_TYPE_TOMATILLO) {
1627                 /* TOMATILLO lacks streaming cache.  */
1628                 return;
1629         }
1630
1631         /* SCHIZO has context flushing. */
1632         pbm->stc.strbuf_control         = base + SCHIZO_STRBUF_CONTROL;
1633         pbm->stc.strbuf_pflush          = base + SCHIZO_STRBUF_FLUSH;
1634         pbm->stc.strbuf_fsync           = base + SCHIZO_STRBUF_FSYNC;
1635         pbm->stc.strbuf_ctxflush        = base + SCHIZO_STRBUF_CTXFLUSH;
1636         pbm->stc.strbuf_ctxmatch_base   = base + SCHIZO_STRBUF_CTXMATCH;
1637
1638         pbm->stc.strbuf_flushflag = (volatile unsigned long *)
1639                 ((((unsigned long)&pbm->stc.__flushflag_buf[0])
1640                   + 63UL)
1641                  & ~63UL);
1642         pbm->stc.strbuf_flushflag_pa = (unsigned long)
1643                 __pa(pbm->stc.strbuf_flushflag);
1644
1645         /* Turn off LRU locking and diag mode, enable the
1646          * streaming buffer and leave the rerun-disable
1647          * setting however OBP set it.
1648          */
1649         control = schizo_read(pbm->stc.strbuf_control);
1650         control &= ~(SCHIZO_STRBUF_CTRL_LPTR |
1651                      SCHIZO_STRBUF_CTRL_LENAB |
1652                      SCHIZO_STRBUF_CTRL_DENAB);
1653         control |= SCHIZO_STRBUF_CTRL_ENAB;
1654         schizo_write(pbm->stc.strbuf_control, control);
1655
1656         pbm->stc.strbuf_enabled = 1;
1657 }
1658
1659 #define SCHIZO_IOMMU_CONTROL            (0x00200UL)
1660 #define SCHIZO_IOMMU_TSBBASE            (0x00208UL)
1661 #define SCHIZO_IOMMU_FLUSH              (0x00210UL)
1662 #define SCHIZO_IOMMU_CTXFLUSH           (0x00218UL)
1663
1664 static void schizo_pbm_iommu_init(struct pci_pbm_info *pbm)
1665 {
1666         struct pci_iommu *iommu = pbm->iommu;
1667         unsigned long i, tagbase, database;
1668         u32 vdma[2], dma_mask;
1669         u64 control;
1670         int err, tsbsize;
1671
1672         err = prom_getproperty(pbm->prom_node, "virtual-dma",
1673                                (char *)&vdma[0], sizeof(vdma));
1674         if (err == 0 || err == -1) {
1675                 /* No property, use default values. */
1676                 vdma[0] = 0xc0000000;
1677                 vdma[1] = 0x40000000;
1678         }
1679
1680         dma_mask = vdma[0];
1681         switch (vdma[1]) {
1682                 case 0x20000000:
1683                         dma_mask |= 0x1fffffff;
1684                         tsbsize = 64;
1685                         break;
1686
1687                 case 0x40000000:
1688                         dma_mask |= 0x3fffffff;
1689                         tsbsize = 128;
1690                         break;
1691
1692                 case 0x80000000:
1693                         dma_mask |= 0x7fffffff;
1694                         tsbsize = 128;
1695                         break;
1696
1697                 default:
1698                         prom_printf("SCHIZO: strange virtual-dma size.\n");
1699                         prom_halt();
1700         };
1701
1702         /* Register addresses, SCHIZO has iommu ctx flushing. */
1703         iommu->iommu_control  = pbm->pbm_regs + SCHIZO_IOMMU_CONTROL;
1704         iommu->iommu_tsbbase  = pbm->pbm_regs + SCHIZO_IOMMU_TSBBASE;
1705         iommu->iommu_flush    = pbm->pbm_regs + SCHIZO_IOMMU_FLUSH;
1706         iommu->iommu_ctxflush = pbm->pbm_regs + SCHIZO_IOMMU_CTXFLUSH;
1707
1708         /* We use the main control/status register of SCHIZO as the write
1709          * completion register.
1710          */
1711         iommu->write_complete_reg = pbm->controller_regs + 0x10000UL;
1712
1713         /*
1714          * Invalidate TLB Entries.
1715          */
1716         control = schizo_read(iommu->iommu_control);
1717         control |= SCHIZO_IOMMU_CTRL_DENAB;
1718         schizo_write(iommu->iommu_control, control);
1719
1720         tagbase = SCHIZO_IOMMU_TAG, database = SCHIZO_IOMMU_DATA;
1721
1722         for(i = 0; i < 16; i++) {
1723                 schizo_write(pbm->pbm_regs + tagbase + (i * 8UL), 0);
1724                 schizo_write(pbm->pbm_regs + database + (i * 8UL), 0);
1725         }
1726
1727         /* Leave diag mode enabled for full-flushing done
1728          * in pci_iommu.c
1729          */
1730         pci_iommu_table_init(iommu, tsbsize * 8 * 1024, vdma[0], dma_mask);
1731
1732         schizo_write(iommu->iommu_tsbbase, __pa(iommu->page_table));
1733
1734         control = schizo_read(iommu->iommu_control);
1735         control &= ~(SCHIZO_IOMMU_CTRL_TSBSZ | SCHIZO_IOMMU_CTRL_TBWSZ);
1736         switch (tsbsize) {
1737         case 64:
1738                 control |= SCHIZO_IOMMU_TSBSZ_64K;
1739                 break;
1740         case 128:
1741                 control |= SCHIZO_IOMMU_TSBSZ_128K;
1742                 break;
1743         };
1744
1745         control |= SCHIZO_IOMMU_CTRL_ENAB;
1746         schizo_write(iommu->iommu_control, control);
1747 }
1748
1749 #define SCHIZO_PCI_IRQ_RETRY    (0x1a00UL)
1750 #define  SCHIZO_IRQ_RETRY_INF    0xffUL
1751
1752 #define SCHIZO_PCI_DIAG                 (0x2020UL)
1753 #define  SCHIZO_PCIDIAG_D_BADECC        (1UL << 10UL) /* Disable BAD ECC errors (Schizo) */
1754 #define  SCHIZO_PCIDIAG_D_BYPASS        (1UL <<  9UL) /* Disable MMU bypass mode (Schizo/Tomatillo) */
1755 #define  SCHIZO_PCIDIAG_D_TTO           (1UL <<  8UL) /* Disable TTO errors (Schizo/Tomatillo) */
1756 #define  SCHIZO_PCIDIAG_D_RTRYARB       (1UL <<  7UL) /* Disable retry arbitration (Schizo) */
1757 #define  SCHIZO_PCIDIAG_D_RETRY         (1UL <<  6UL) /* Disable retry limit (Schizo/Tomatillo) */
1758 #define  SCHIZO_PCIDIAG_D_INTSYNC       (1UL <<  5UL) /* Disable interrupt/DMA synch (Schizo/Tomatillo) */
1759 #define  SCHIZO_PCIDIAG_I_DMA_PARITY    (1UL <<  3UL) /* Invert DMA parity (Schizo/Tomatillo) */
1760 #define  SCHIZO_PCIDIAG_I_PIOD_PARITY   (1UL <<  2UL) /* Invert PIO data parity (Schizo/Tomatillo) */
1761 #define  SCHIZO_PCIDIAG_I_PIOA_PARITY   (1UL <<  1UL) /* Invert PIO address parity (Schizo/Tomatillo) */
1762
1763 #define TOMATILLO_PCI_IOC_CSR           (0x2248UL)
1764 #define TOMATILLO_IOC_PART_WPENAB       0x0000000000080000UL
1765 #define TOMATILLO_IOC_RDMULT_PENAB      0x0000000000040000UL
1766 #define TOMATILLO_IOC_RDONE_PENAB       0x0000000000020000UL
1767 #define TOMATILLO_IOC_RDLINE_PENAB      0x0000000000010000UL
1768 #define TOMATILLO_IOC_RDMULT_PLEN       0x000000000000c000UL
1769 #define TOMATILLO_IOC_RDMULT_PLEN_SHIFT 14UL
1770 #define TOMATILLO_IOC_RDONE_PLEN        0x0000000000003000UL
1771 #define TOMATILLO_IOC_RDONE_PLEN_SHIFT  12UL
1772 #define TOMATILLO_IOC_RDLINE_PLEN       0x0000000000000c00UL
1773 #define TOMATILLO_IOC_RDLINE_PLEN_SHIFT 10UL
1774 #define TOMATILLO_IOC_PREF_OFF          0x00000000000003f8UL
1775 #define TOMATILLO_IOC_PREF_OFF_SHIFT    3UL
1776 #define TOMATILLO_IOC_RDMULT_CPENAB     0x0000000000000004UL
1777 #define TOMATILLO_IOC_RDONE_CPENAB      0x0000000000000002UL
1778 #define TOMATILLO_IOC_RDLINE_CPENAB     0x0000000000000001UL
1779
1780 #define TOMATILLO_PCI_IOC_TDIAG         (0x2250UL)
1781 #define TOMATILLO_PCI_IOC_DDIAG         (0x2290UL)
1782
1783 static void schizo_pbm_hw_init(struct pci_pbm_info *pbm)
1784 {
1785         u64 tmp;
1786
1787         schizo_write(pbm->pbm_regs + SCHIZO_PCI_IRQ_RETRY, 5);
1788
1789         tmp = schizo_read(pbm->pbm_regs + SCHIZO_PCI_CTRL);
1790
1791         /* Enable arbiter for all PCI slots.  */
1792         tmp |= 0xff;
1793
1794         if (pbm->chip_type == PBM_CHIP_TYPE_TOMATILLO &&
1795             pbm->chip_version >= 0x2)
1796                 tmp |= 0x3UL << SCHIZO_PCICTRL_PTO_SHIFT;
1797
1798         if (!prom_getbool(pbm->prom_node, "no-bus-parking"))
1799                 tmp |= SCHIZO_PCICTRL_PARK;
1800         else
1801                 tmp &= ~SCHIZO_PCICTRL_PARK;
1802
1803         if (pbm->chip_type == PBM_CHIP_TYPE_TOMATILLO &&
1804             pbm->chip_version <= 0x1)
1805                 tmp |= SCHIZO_PCICTRL_DTO_INT;
1806         else
1807                 tmp &= ~SCHIZO_PCICTRL_DTO_INT;
1808
1809         if (pbm->chip_type == PBM_CHIP_TYPE_TOMATILLO)
1810                 tmp |= (SCHIZO_PCICTRL_MRM_PREF |
1811                         SCHIZO_PCICTRL_RDO_PREF |
1812                         SCHIZO_PCICTRL_RDL_PREF);
1813
1814         schizo_write(pbm->pbm_regs + SCHIZO_PCI_CTRL, tmp);
1815
1816         tmp = schizo_read(pbm->pbm_regs + SCHIZO_PCI_DIAG);
1817         tmp &= ~(SCHIZO_PCIDIAG_D_RTRYARB |
1818                  SCHIZO_PCIDIAG_D_RETRY |
1819                  SCHIZO_PCIDIAG_D_INTSYNC);
1820         schizo_write(pbm->pbm_regs + SCHIZO_PCI_DIAG, tmp);
1821
1822         if (pbm->chip_type == PBM_CHIP_TYPE_TOMATILLO) {
1823                 /* Clear prefetch lengths to workaround a bug in
1824                  * Jalapeno...
1825                  */
1826                 tmp = (TOMATILLO_IOC_PART_WPENAB |
1827                        (1 << TOMATILLO_IOC_PREF_OFF_SHIFT) |
1828                        TOMATILLO_IOC_RDMULT_CPENAB |
1829                        TOMATILLO_IOC_RDONE_CPENAB |
1830                        TOMATILLO_IOC_RDLINE_CPENAB);
1831
1832                 schizo_write(pbm->pbm_regs + TOMATILLO_PCI_IOC_CSR,
1833                              tmp);
1834         }
1835 }
1836
1837 static void schizo_pbm_init(struct pci_controller_info *p,
1838                             int prom_node, u32 portid,
1839                             int chip_type)
1840 {
1841         struct linux_prom64_registers pr_regs[4];
1842         unsigned int busrange[2];
1843         struct pci_pbm_info *pbm;
1844         const char *chipset_name;
1845         u32 ino_bitmap[2];
1846         int is_pbm_a;
1847         int err;
1848
1849         switch (chip_type) {
1850         case PBM_CHIP_TYPE_TOMATILLO:
1851                 chipset_name = "TOMATILLO";
1852                 break;
1853
1854         case PBM_CHIP_TYPE_SCHIZO_PLUS:
1855                 chipset_name = "SCHIZO+";
1856                 break;
1857
1858         case PBM_CHIP_TYPE_SCHIZO:
1859         default:
1860                 chipset_name = "SCHIZO";
1861                 break;
1862         };
1863
1864         /* For SCHIZO, three OBP regs:
1865          * 1) PBM controller regs
1866          * 2) Schizo front-end controller regs (same for both PBMs)
1867          * 3) PBM PCI config space
1868          *
1869          * For TOMATILLO, four OBP regs:
1870          * 1) PBM controller regs
1871          * 2) Tomatillo front-end controller regs
1872          * 3) PBM PCI config space
1873          * 4) Ichip regs
1874          */
1875         err = prom_getproperty(prom_node, "reg",
1876                                (char *)&pr_regs[0],
1877                                sizeof(pr_regs));
1878         if (err == 0 || err == -1) {
1879                 prom_printf("%s: Fatal error, no reg property.\n",
1880                             chipset_name);
1881                 prom_halt();
1882         }
1883
1884         is_pbm_a = ((pr_regs[0].phys_addr & 0x00700000) == 0x00600000);
1885
1886         if (is_pbm_a)
1887                 pbm = &p->pbm_A;
1888         else
1889                 pbm = &p->pbm_B;
1890
1891         pbm->portid = portid;
1892         pbm->parent = p;
1893         pbm->prom_node = prom_node;
1894         pbm->pci_first_slot = 1;
1895
1896         pbm->chip_type = chip_type;
1897         pbm->chip_version =
1898                 prom_getintdefault(prom_node, "version#", 0);
1899         pbm->chip_revision =
1900                 prom_getintdefault(prom_node, "module-revision#", 0);
1901
1902         pbm->pbm_regs = pr_regs[0].phys_addr;
1903         pbm->controller_regs = pr_regs[1].phys_addr - 0x10000UL;
1904
1905         if (chip_type == PBM_CHIP_TYPE_TOMATILLO)
1906                 pbm->sync_reg = pr_regs[3].phys_addr + 0x1a18UL;
1907
1908         sprintf(pbm->name,
1909                 (chip_type == PBM_CHIP_TYPE_TOMATILLO ?
1910                  "TOMATILLO%d PBM%c" :
1911                  "SCHIZO%d PBM%c"),
1912                 p->index,
1913                 (pbm == &p->pbm_A ? 'A' : 'B'));
1914
1915         printk("%s: ver[%x:%x], portid %x, "
1916                "cregs[%lx] pregs[%lx]\n",
1917                pbm->name,
1918                pbm->chip_version, pbm->chip_revision,
1919                pbm->portid,
1920                pbm->controller_regs,
1921                pbm->pbm_regs);
1922
1923         schizo_pbm_hw_init(pbm);
1924
1925         prom_getstring(prom_node, "name",
1926                        pbm->prom_name,
1927                        sizeof(pbm->prom_name));
1928
1929         err = prom_getproperty(prom_node, "ranges",
1930                                (char *) pbm->pbm_ranges,
1931                                sizeof(pbm->pbm_ranges));
1932         if (err == 0 || err == -1) {
1933                 prom_printf("%s: Fatal error, no ranges property.\n",
1934                             pbm->name);
1935                 prom_halt();
1936         }
1937
1938         pbm->num_pbm_ranges =
1939                 (err / sizeof(struct linux_prom_pci_ranges));
1940
1941         schizo_determine_mem_io_space(pbm);
1942         pbm_register_toplevel_resources(p, pbm);
1943
1944         err = prom_getproperty(prom_node, "interrupt-map",
1945                                (char *)pbm->pbm_intmap,
1946                                sizeof(pbm->pbm_intmap));
1947         if (err != -1) {
1948                 pbm->num_pbm_intmap = (err / sizeof(struct linux_prom_pci_intmap));
1949                 err = prom_getproperty(prom_node, "interrupt-map-mask",
1950                                        (char *)&pbm->pbm_intmask,
1951                                        sizeof(pbm->pbm_intmask));
1952                 if (err == -1) {
1953                         prom_printf("%s: Fatal error, no "
1954                                     "interrupt-map-mask.\n", pbm->name);
1955                         prom_halt();
1956                 }
1957         } else {
1958                 pbm->num_pbm_intmap = 0;
1959                 memset(&pbm->pbm_intmask, 0, sizeof(pbm->pbm_intmask));
1960         }
1961
1962         err = prom_getproperty(prom_node, "ino-bitmap",
1963                                (char *) &ino_bitmap[0],
1964                                sizeof(ino_bitmap));
1965         if (err == 0 || err == -1) {
1966                 prom_printf("%s: Fatal error, no ino-bitmap.\n", pbm->name);
1967                 prom_halt();
1968         }
1969         pbm->ino_bitmap = (((u64)ino_bitmap[1] << 32UL) |
1970                            ((u64)ino_bitmap[0] <<  0UL));
1971
1972         err = prom_getproperty(prom_node, "bus-range",
1973                                (char *)&busrange[0],
1974                                sizeof(busrange));
1975         if (err == 0 || err == -1) {
1976                 prom_printf("%s: Fatal error, no bus-range.\n", pbm->name);
1977                 prom_halt();
1978         }
1979         pbm->pci_first_busno = busrange[0];
1980         pbm->pci_last_busno = busrange[1];
1981
1982         schizo_pbm_iommu_init(pbm);
1983         schizo_pbm_strbuf_init(pbm);
1984 }
1985
1986 static inline int portid_compare(u32 x, u32 y, int chip_type)
1987 {
1988         if (chip_type == PBM_CHIP_TYPE_TOMATILLO) {
1989                 if (x == (y ^ 1))
1990                         return 1;
1991                 return 0;
1992         }
1993         return (x == y);
1994 }
1995
1996 static void __schizo_init(int node, char *model_name, int chip_type)
1997 {
1998         struct pci_controller_info *p;
1999         struct pci_iommu *iommu;
2000         int is_pbm_a;
2001         u32 portid;
2002
2003         portid = prom_getintdefault(node, "portid", 0xff);
2004
2005         for(p = pci_controller_root; p; p = p->next) {
2006                 struct pci_pbm_info *pbm;
2007
2008                 if (p->pbm_A.prom_node && p->pbm_B.prom_node)
2009                         continue;
2010
2011                 pbm = (p->pbm_A.prom_node ?
2012                        &p->pbm_A :
2013                        &p->pbm_B);
2014
2015                 if (portid_compare(pbm->portid, portid, chip_type)) {
2016                         is_pbm_a = (p->pbm_A.prom_node == 0);
2017                         schizo_pbm_init(p, node, portid, chip_type);
2018                         return;
2019                 }
2020         }
2021
2022         p = kzalloc(sizeof(struct pci_controller_info), GFP_ATOMIC);
2023         if (!p) {
2024                 prom_printf("SCHIZO: Fatal memory allocation error.\n");
2025                 prom_halt();
2026         }
2027
2028         iommu = kzalloc(sizeof(struct pci_iommu), GFP_ATOMIC);
2029         if (!iommu) {
2030                 prom_printf("SCHIZO: Fatal memory allocation error.\n");
2031                 prom_halt();
2032         }
2033         p->pbm_A.iommu = iommu;
2034
2035         iommu = kzalloc(sizeof(struct pci_iommu), GFP_ATOMIC);
2036         if (!iommu) {
2037                 prom_printf("SCHIZO: Fatal memory allocation error.\n");
2038                 prom_halt();
2039         }
2040         p->pbm_B.iommu = iommu;
2041
2042         p->next = pci_controller_root;
2043         pci_controller_root = p;
2044
2045         p->index = pci_num_controllers++;
2046         p->pbms_same_domain = 0;
2047         p->scan_bus = (chip_type == PBM_CHIP_TYPE_TOMATILLO ?
2048                        tomatillo_scan_bus :
2049                        schizo_scan_bus);
2050         p->irq_build = schizo_irq_build;
2051         p->base_address_update = schizo_base_address_update;
2052         p->resource_adjust = schizo_resource_adjust;
2053         p->pci_ops = &schizo_ops;
2054
2055         /* Like PSYCHO we have a 2GB aligned area for memory space. */
2056         pci_memspace_mask = 0x7fffffffUL;
2057
2058         schizo_pbm_init(p, node, portid, chip_type);
2059 }
2060
2061 void schizo_init(int node, char *model_name)
2062 {
2063         __schizo_init(node, model_name, PBM_CHIP_TYPE_SCHIZO);
2064 }
2065
2066 void schizo_plus_init(int node, char *model_name)
2067 {
2068         __schizo_init(node, model_name, PBM_CHIP_TYPE_SCHIZO_PLUS);
2069 }
2070
2071 void tomatillo_init(int node, char *model_name)
2072 {
2073         __schizo_init(node, model_name, PBM_CHIP_TYPE_TOMATILLO);
2074 }