blob: 72743acecbc039740d4a689d7135ccff0260e561 [file] [log] [blame]
David S. Miller9fd8b642007-03-08 21:55:49 -08001/* pci_schizo.c: SCHIZO/TOMATILLO specific PCI controller support.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
David S. Miller9fd8b642007-03-08 21:55:49 -08003 * Copyright (C) 2001, 2002, 2003, 2007 David S. Miller (davem@davemloft.net)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 */
5
6#include <linux/kernel.h>
7#include <linux/types.h>
8#include <linux/pci.h>
9#include <linux/init.h>
10#include <linux/slab.h>
11#include <linux/interrupt.h>
12
13#include <asm/pbm.h>
14#include <asm/iommu.h>
15#include <asm/irq.h>
16#include <asm/upa.h>
David S. Millerbb6743f2005-07-04 13:26:04 -070017#include <asm/pstate.h>
David S. Millere87dc352006-06-21 18:18:47 -070018#include <asm/prom.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
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
93static 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. */
107static 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
119static 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
David S. Miller97b3cf02007-03-11 16:42:53 -0700128 if (bus_dev == pbm->pci_bus && devfn == 0x00)
129 return pci_host_bridge_read_pci_cfg(bus_dev, devfn, where,
130 size, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 switch (size) {
132 case 1:
133 *value = 0xff;
134 break;
135 case 2:
136 *value = 0xffff;
137 break;
138 case 4:
139 *value = 0xffffffff;
140 break;
141 }
142
143 addr = schizo_pci_config_mkaddr(pbm, bus, devfn, where);
144 if (!addr)
145 return PCIBIOS_SUCCESSFUL;
146
147 if (schizo_out_of_range(pbm, bus, devfn))
148 return PCIBIOS_SUCCESSFUL;
149 switch (size) {
150 case 1:
151 pci_config_read8((u8 *)addr, &tmp8);
152 *value = tmp8;
153 break;
154
155 case 2:
156 if (where & 0x01) {
157 printk("pci_read_config_word: misaligned reg [%x]\n",
158 where);
159 return PCIBIOS_SUCCESSFUL;
160 }
161 pci_config_read16((u16 *)addr, &tmp16);
162 *value = tmp16;
163 break;
164
165 case 4:
166 if (where & 0x03) {
167 printk("pci_read_config_dword: misaligned reg [%x]\n",
168 where);
169 return PCIBIOS_SUCCESSFUL;
170 }
171 pci_config_read32(addr, value);
172 break;
173 }
174 return PCIBIOS_SUCCESSFUL;
175}
176
177static int schizo_write_pci_cfg(struct pci_bus *bus_dev, unsigned int devfn,
178 int where, int size, u32 value)
179{
180 struct pci_pbm_info *pbm = bus_dev->sysdata;
181 unsigned char bus = bus_dev->number;
182 u32 *addr;
183
David S. Miller97b3cf02007-03-11 16:42:53 -0700184 if (bus_dev == pbm->pci_bus && devfn == 0x00)
185 return pci_host_bridge_write_pci_cfg(bus_dev, devfn, where,
186 size, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 addr = schizo_pci_config_mkaddr(pbm, bus, devfn, where);
188 if (!addr)
189 return PCIBIOS_SUCCESSFUL;
190
191 if (schizo_out_of_range(pbm, bus, devfn))
192 return PCIBIOS_SUCCESSFUL;
193
194 switch (size) {
195 case 1:
196 pci_config_write8((u8 *)addr, value);
197 break;
198
199 case 2:
200 if (where & 0x01) {
201 printk("pci_write_config_word: misaligned reg [%x]\n",
202 where);
203 return PCIBIOS_SUCCESSFUL;
204 }
205 pci_config_write16((u16 *)addr, value);
206 break;
207
208 case 4:
209 if (where & 0x03) {
210 printk("pci_write_config_dword: misaligned reg [%x]\n",
211 where);
212 return PCIBIOS_SUCCESSFUL;
213 }
214
215 pci_config_write32(addr, value);
216 }
217 return PCIBIOS_SUCCESSFUL;
218}
219
220static struct pci_ops schizo_ops = {
221 .read = schizo_read_pci_cfg,
222 .write = schizo_write_pci_cfg,
223};
224
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225/* SCHIZO error handling support. */
226enum schizo_error_type {
227 UE_ERR, CE_ERR, PCI_ERR, SAFARI_ERR
228};
229
230static DEFINE_SPINLOCK(stc_buf_lock);
231static unsigned long stc_error_buf[128];
232static unsigned long stc_tag_buf[16];
233static unsigned long stc_line_buf[16];
234
235#define SCHIZO_UE_INO 0x30 /* Uncorrectable ECC error */
236#define SCHIZO_CE_INO 0x31 /* Correctable ECC error */
237#define SCHIZO_PCIERR_A_INO 0x32 /* PBM A PCI bus error */
238#define SCHIZO_PCIERR_B_INO 0x33 /* PBM B PCI bus error */
239#define SCHIZO_SERR_INO 0x34 /* Safari interface error */
240
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241#define SCHIZO_STC_ERR 0xb800UL /* --> 0xba00 */
242#define SCHIZO_STC_TAG 0xba00UL /* --> 0xba80 */
243#define SCHIZO_STC_LINE 0xbb00UL /* --> 0xbb80 */
244
245#define SCHIZO_STCERR_WRITE 0x2UL
246#define SCHIZO_STCERR_READ 0x1UL
247
248#define SCHIZO_STCTAG_PPN 0x3fffffff00000000UL
249#define SCHIZO_STCTAG_VPN 0x00000000ffffe000UL
250#define SCHIZO_STCTAG_VALID 0x8000000000000000UL
251#define SCHIZO_STCTAG_READ 0x4000000000000000UL
252
253#define SCHIZO_STCLINE_LINDX 0x0000000007800000UL
254#define SCHIZO_STCLINE_SPTR 0x000000000007e000UL
255#define SCHIZO_STCLINE_LADDR 0x0000000000001fc0UL
256#define SCHIZO_STCLINE_EPTR 0x000000000000003fUL
257#define SCHIZO_STCLINE_VALID 0x0000000000600000UL
258#define SCHIZO_STCLINE_FOFN 0x0000000000180000UL
259
260static void __schizo_check_stc_error_pbm(struct pci_pbm_info *pbm,
261 enum schizo_error_type type)
262{
David S. Miller16ce82d2007-04-26 21:08:21 -0700263 struct strbuf *strbuf = &pbm->stc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 unsigned long regbase = pbm->pbm_regs;
265 unsigned long err_base, tag_base, line_base;
266 u64 control;
267 int i;
268
269 err_base = regbase + SCHIZO_STC_ERR;
270 tag_base = regbase + SCHIZO_STC_TAG;
271 line_base = regbase + SCHIZO_STC_LINE;
272
273 spin_lock(&stc_buf_lock);
274
275 /* This is __REALLY__ dangerous. When we put the
276 * streaming buffer into diagnostic mode to probe
277 * it's tags and error status, we _must_ clear all
278 * of the line tag valid bits before re-enabling
279 * the streaming buffer. If any dirty data lives
280 * in the STC when we do this, we will end up
281 * invalidating it before it has a chance to reach
282 * main memory.
283 */
284 control = schizo_read(strbuf->strbuf_control);
285 schizo_write(strbuf->strbuf_control,
286 (control | SCHIZO_STRBUF_CTRL_DENAB));
287 for (i = 0; i < 128; i++) {
288 unsigned long val;
289
290 val = schizo_read(err_base + (i * 8UL));
291 schizo_write(err_base + (i * 8UL), 0UL);
292 stc_error_buf[i] = val;
293 }
294 for (i = 0; i < 16; i++) {
295 stc_tag_buf[i] = schizo_read(tag_base + (i * 8UL));
296 stc_line_buf[i] = schizo_read(line_base + (i * 8UL));
297 schizo_write(tag_base + (i * 8UL), 0UL);
298 schizo_write(line_base + (i * 8UL), 0UL);
299 }
300
301 /* OK, state is logged, exit diagnostic mode. */
302 schizo_write(strbuf->strbuf_control, control);
303
304 for (i = 0; i < 16; i++) {
305 int j, saw_error, first, last;
306
307 saw_error = 0;
308 first = i * 8;
309 last = first + 8;
310 for (j = first; j < last; j++) {
311 unsigned long errval = stc_error_buf[j];
312 if (errval != 0) {
313 saw_error++;
314 printk("%s: STC_ERR(%d)[wr(%d)rd(%d)]\n",
315 pbm->name,
316 j,
317 (errval & SCHIZO_STCERR_WRITE) ? 1 : 0,
318 (errval & SCHIZO_STCERR_READ) ? 1 : 0);
319 }
320 }
321 if (saw_error != 0) {
322 unsigned long tagval = stc_tag_buf[i];
323 unsigned long lineval = stc_line_buf[i];
324 printk("%s: STC_TAG(%d)[PA(%016lx)VA(%08lx)V(%d)R(%d)]\n",
325 pbm->name,
326 i,
327 ((tagval & SCHIZO_STCTAG_PPN) >> 19UL),
328 (tagval & SCHIZO_STCTAG_VPN),
329 ((tagval & SCHIZO_STCTAG_VALID) ? 1 : 0),
330 ((tagval & SCHIZO_STCTAG_READ) ? 1 : 0));
331
332 /* XXX Should spit out per-bank error information... -DaveM */
333 printk("%s: STC_LINE(%d)[LIDX(%lx)SP(%lx)LADDR(%lx)EP(%lx)"
334 "V(%d)FOFN(%d)]\n",
335 pbm->name,
336 i,
337 ((lineval & SCHIZO_STCLINE_LINDX) >> 23UL),
338 ((lineval & SCHIZO_STCLINE_SPTR) >> 13UL),
339 ((lineval & SCHIZO_STCLINE_LADDR) >> 6UL),
340 ((lineval & SCHIZO_STCLINE_EPTR) >> 0UL),
341 ((lineval & SCHIZO_STCLINE_VALID) ? 1 : 0),
342 ((lineval & SCHIZO_STCLINE_FOFN) ? 1 : 0));
343 }
344 }
345
346 spin_unlock(&stc_buf_lock);
347}
348
349/* IOMMU is per-PBM in Schizo, so interrogate both for anonymous
350 * controller level errors.
351 */
352
353#define SCHIZO_IOMMU_TAG 0xa580UL
354#define SCHIZO_IOMMU_DATA 0xa600UL
355
356#define SCHIZO_IOMMU_TAG_CTXT 0x0000001ffe000000UL
357#define SCHIZO_IOMMU_TAG_ERRSTS 0x0000000001800000UL
358#define SCHIZO_IOMMU_TAG_ERR 0x0000000000400000UL
359#define SCHIZO_IOMMU_TAG_WRITE 0x0000000000200000UL
360#define SCHIZO_IOMMU_TAG_STREAM 0x0000000000100000UL
361#define SCHIZO_IOMMU_TAG_SIZE 0x0000000000080000UL
362#define SCHIZO_IOMMU_TAG_VPAGE 0x000000000007ffffUL
363
364#define SCHIZO_IOMMU_DATA_VALID 0x0000000100000000UL
365#define SCHIZO_IOMMU_DATA_CACHE 0x0000000040000000UL
366#define SCHIZO_IOMMU_DATA_PPAGE 0x000000003fffffffUL
367
368static void schizo_check_iommu_error_pbm(struct pci_pbm_info *pbm,
369 enum schizo_error_type type)
370{
David S. Miller16ce82d2007-04-26 21:08:21 -0700371 struct iommu *iommu = pbm->iommu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 unsigned long iommu_tag[16];
373 unsigned long iommu_data[16];
374 unsigned long flags;
375 u64 control;
376 int i;
377
378 spin_lock_irqsave(&iommu->lock, flags);
379 control = schizo_read(iommu->iommu_control);
380 if (control & SCHIZO_IOMMU_CTRL_XLTEERR) {
381 unsigned long base;
382 char *type_string;
383
384 /* Clear the error encountered bit. */
385 control &= ~SCHIZO_IOMMU_CTRL_XLTEERR;
386 schizo_write(iommu->iommu_control, control);
387
388 switch((control & SCHIZO_IOMMU_CTRL_XLTESTAT) >> 25UL) {
389 case 0:
390 type_string = "Protection Error";
391 break;
392 case 1:
393 type_string = "Invalid Error";
394 break;
395 case 2:
396 type_string = "TimeOut Error";
397 break;
398 case 3:
399 default:
400 type_string = "ECC Error";
401 break;
402 };
403 printk("%s: IOMMU Error, type[%s]\n",
404 pbm->name, type_string);
405
406 /* Put the IOMMU into diagnostic mode and probe
407 * it's TLB for entries with error status.
408 *
409 * It is very possible for another DVMA to occur
410 * while we do this probe, and corrupt the system
411 * further. But we are so screwed at this point
412 * that we are likely to crash hard anyways, so
413 * get as much diagnostic information to the
414 * console as we can.
415 */
416 schizo_write(iommu->iommu_control,
417 control | SCHIZO_IOMMU_CTRL_DENAB);
418
419 base = pbm->pbm_regs;
420
421 for (i = 0; i < 16; i++) {
422 iommu_tag[i] =
423 schizo_read(base + SCHIZO_IOMMU_TAG + (i * 8UL));
424 iommu_data[i] =
425 schizo_read(base + SCHIZO_IOMMU_DATA + (i * 8UL));
426
427 /* Now clear out the entry. */
428 schizo_write(base + SCHIZO_IOMMU_TAG + (i * 8UL), 0);
429 schizo_write(base + SCHIZO_IOMMU_DATA + (i * 8UL), 0);
430 }
431
432 /* Leave diagnostic mode. */
433 schizo_write(iommu->iommu_control, control);
434
435 for (i = 0; i < 16; i++) {
436 unsigned long tag, data;
437
438 tag = iommu_tag[i];
439 if (!(tag & SCHIZO_IOMMU_TAG_ERR))
440 continue;
441
442 data = iommu_data[i];
443 switch((tag & SCHIZO_IOMMU_TAG_ERRSTS) >> 23UL) {
444 case 0:
445 type_string = "Protection Error";
446 break;
447 case 1:
448 type_string = "Invalid Error";
449 break;
450 case 2:
451 type_string = "TimeOut Error";
452 break;
453 case 3:
454 default:
455 type_string = "ECC Error";
456 break;
457 };
458 printk("%s: IOMMU TAG(%d)[error(%s) ctx(%x) wr(%d) str(%d) "
459 "sz(%dK) vpg(%08lx)]\n",
460 pbm->name, i, type_string,
461 (int)((tag & SCHIZO_IOMMU_TAG_CTXT) >> 25UL),
462 ((tag & SCHIZO_IOMMU_TAG_WRITE) ? 1 : 0),
463 ((tag & SCHIZO_IOMMU_TAG_STREAM) ? 1 : 0),
464 ((tag & SCHIZO_IOMMU_TAG_SIZE) ? 64 : 8),
465 (tag & SCHIZO_IOMMU_TAG_VPAGE) << IOMMU_PAGE_SHIFT);
466 printk("%s: IOMMU DATA(%d)[valid(%d) cache(%d) ppg(%016lx)]\n",
467 pbm->name, i,
468 ((data & SCHIZO_IOMMU_DATA_VALID) ? 1 : 0),
469 ((data & SCHIZO_IOMMU_DATA_CACHE) ? 1 : 0),
470 (data & SCHIZO_IOMMU_DATA_PPAGE) << IOMMU_PAGE_SHIFT);
471 }
472 }
473 if (pbm->stc.strbuf_enabled)
474 __schizo_check_stc_error_pbm(pbm, type);
475 spin_unlock_irqrestore(&iommu->lock, flags);
476}
477
478static void schizo_check_iommu_error(struct pci_controller_info *p,
479 enum schizo_error_type type)
480{
481 schizo_check_iommu_error_pbm(&p->pbm_A, type);
482 schizo_check_iommu_error_pbm(&p->pbm_B, type);
483}
484
485/* Uncorrectable ECC error status gathering. */
486#define SCHIZO_UE_AFSR 0x10030UL
487#define SCHIZO_UE_AFAR 0x10038UL
488
489#define SCHIZO_UEAFSR_PPIO 0x8000000000000000UL /* Safari */
490#define SCHIZO_UEAFSR_PDRD 0x4000000000000000UL /* Safari/Tomatillo */
491#define SCHIZO_UEAFSR_PDWR 0x2000000000000000UL /* Safari */
492#define SCHIZO_UEAFSR_SPIO 0x1000000000000000UL /* Safari */
493#define SCHIZO_UEAFSR_SDMA 0x0800000000000000UL /* Safari/Tomatillo */
494#define SCHIZO_UEAFSR_ERRPNDG 0x0300000000000000UL /* Safari */
495#define SCHIZO_UEAFSR_BMSK 0x000003ff00000000UL /* Safari */
496#define SCHIZO_UEAFSR_QOFF 0x00000000c0000000UL /* Safari/Tomatillo */
497#define SCHIZO_UEAFSR_AID 0x000000001f000000UL /* Safari/Tomatillo */
498#define SCHIZO_UEAFSR_PARTIAL 0x0000000000800000UL /* Safari */
499#define SCHIZO_UEAFSR_OWNEDIN 0x0000000000400000UL /* Safari */
500#define SCHIZO_UEAFSR_MTAGSYND 0x00000000000f0000UL /* Safari */
501#define SCHIZO_UEAFSR_MTAG 0x000000000000e000UL /* Safari */
502#define SCHIZO_UEAFSR_ECCSYND 0x00000000000001ffUL /* Safari */
503
Al Viro6d24c8d2006-10-08 08:23:28 -0400504static irqreturn_t schizo_ue_intr(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505{
David S. Miller34768bc2007-05-07 23:06:27 -0700506 struct pci_pbm_info *pbm = dev_id;
507 struct pci_controller_info *p = pbm->parent;
508 unsigned long afsr_reg = pbm->controller_regs + SCHIZO_UE_AFSR;
509 unsigned long afar_reg = pbm->controller_regs + SCHIZO_UE_AFAR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 unsigned long afsr, afar, error_bits;
511 int reported, limit;
512
513 /* Latch uncorrectable error status. */
514 afar = schizo_read(afar_reg);
515
516 /* If either of the error pending bits are set in the
517 * AFSR, the error status is being actively updated by
518 * the hardware and we must re-read to get a clean value.
519 */
520 limit = 1000;
521 do {
522 afsr = schizo_read(afsr_reg);
523 } while ((afsr & SCHIZO_UEAFSR_ERRPNDG) != 0 && --limit);
524
525 /* Clear the primary/secondary error status bits. */
526 error_bits = afsr &
527 (SCHIZO_UEAFSR_PPIO | SCHIZO_UEAFSR_PDRD | SCHIZO_UEAFSR_PDWR |
528 SCHIZO_UEAFSR_SPIO | SCHIZO_UEAFSR_SDMA);
529 if (!error_bits)
530 return IRQ_NONE;
531 schizo_write(afsr_reg, error_bits);
532
533 /* Log the error. */
David S. Miller6c108f12007-05-07 23:49:01 -0700534 printk("%s: Uncorrectable Error, primary error type[%s]\n",
535 pbm->name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 (((error_bits & SCHIZO_UEAFSR_PPIO) ?
537 "PIO" :
538 ((error_bits & SCHIZO_UEAFSR_PDRD) ?
539 "DMA Read" :
540 ((error_bits & SCHIZO_UEAFSR_PDWR) ?
541 "DMA Write" : "???")))));
David S. Miller6c108f12007-05-07 23:49:01 -0700542 printk("%s: bytemask[%04lx] qword_offset[%lx] SAFARI_AID[%02lx]\n",
543 pbm->name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 (afsr & SCHIZO_UEAFSR_BMSK) >> 32UL,
545 (afsr & SCHIZO_UEAFSR_QOFF) >> 30UL,
546 (afsr & SCHIZO_UEAFSR_AID) >> 24UL);
David S. Miller6c108f12007-05-07 23:49:01 -0700547 printk("%s: partial[%d] owned_in[%d] mtag[%lx] mtag_synd[%lx] ecc_sync[%lx]\n",
548 pbm->name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 (afsr & SCHIZO_UEAFSR_PARTIAL) ? 1 : 0,
550 (afsr & SCHIZO_UEAFSR_OWNEDIN) ? 1 : 0,
551 (afsr & SCHIZO_UEAFSR_MTAG) >> 13UL,
552 (afsr & SCHIZO_UEAFSR_MTAGSYND) >> 16UL,
553 (afsr & SCHIZO_UEAFSR_ECCSYND) >> 0UL);
David S. Miller6c108f12007-05-07 23:49:01 -0700554 printk("%s: UE AFAR [%016lx]\n", pbm->name, afar);
555 printk("%s: UE Secondary errors [", pbm->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 reported = 0;
557 if (afsr & SCHIZO_UEAFSR_SPIO) {
558 reported++;
559 printk("(PIO)");
560 }
561 if (afsr & SCHIZO_UEAFSR_SDMA) {
562 reported++;
563 printk("(DMA)");
564 }
565 if (!reported)
566 printk("(none)");
567 printk("]\n");
568
569 /* Interrogate IOMMU for error status. */
570 schizo_check_iommu_error(p, UE_ERR);
571
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 return IRQ_HANDLED;
573}
574
575#define SCHIZO_CE_AFSR 0x10040UL
576#define SCHIZO_CE_AFAR 0x10048UL
577
578#define SCHIZO_CEAFSR_PPIO 0x8000000000000000UL
579#define SCHIZO_CEAFSR_PDRD 0x4000000000000000UL
580#define SCHIZO_CEAFSR_PDWR 0x2000000000000000UL
581#define SCHIZO_CEAFSR_SPIO 0x1000000000000000UL
582#define SCHIZO_CEAFSR_SDMA 0x0800000000000000UL
583#define SCHIZO_CEAFSR_ERRPNDG 0x0300000000000000UL
584#define SCHIZO_CEAFSR_BMSK 0x000003ff00000000UL
585#define SCHIZO_CEAFSR_QOFF 0x00000000c0000000UL
586#define SCHIZO_CEAFSR_AID 0x000000001f000000UL
587#define SCHIZO_CEAFSR_PARTIAL 0x0000000000800000UL
588#define SCHIZO_CEAFSR_OWNEDIN 0x0000000000400000UL
589#define SCHIZO_CEAFSR_MTAGSYND 0x00000000000f0000UL
590#define SCHIZO_CEAFSR_MTAG 0x000000000000e000UL
591#define SCHIZO_CEAFSR_ECCSYND 0x00000000000001ffUL
592
Al Viro6d24c8d2006-10-08 08:23:28 -0400593static irqreturn_t schizo_ce_intr(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594{
David S. Miller34768bc2007-05-07 23:06:27 -0700595 struct pci_pbm_info *pbm = dev_id;
David S. Miller34768bc2007-05-07 23:06:27 -0700596 unsigned long afsr_reg = pbm->controller_regs + SCHIZO_CE_AFSR;
597 unsigned long afar_reg = pbm->controller_regs + SCHIZO_CE_AFAR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 unsigned long afsr, afar, error_bits;
599 int reported, limit;
600
601 /* Latch error status. */
602 afar = schizo_read(afar_reg);
603
604 /* If either of the error pending bits are set in the
605 * AFSR, the error status is being actively updated by
606 * the hardware and we must re-read to get a clean value.
607 */
608 limit = 1000;
609 do {
610 afsr = schizo_read(afsr_reg);
611 } while ((afsr & SCHIZO_UEAFSR_ERRPNDG) != 0 && --limit);
612
613 /* Clear primary/secondary error status bits. */
614 error_bits = afsr &
615 (SCHIZO_CEAFSR_PPIO | SCHIZO_CEAFSR_PDRD | SCHIZO_CEAFSR_PDWR |
616 SCHIZO_CEAFSR_SPIO | SCHIZO_CEAFSR_SDMA);
617 if (!error_bits)
618 return IRQ_NONE;
619 schizo_write(afsr_reg, error_bits);
620
621 /* Log the error. */
David S. Miller6c108f12007-05-07 23:49:01 -0700622 printk("%s: Correctable Error, primary error type[%s]\n",
623 pbm->name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 (((error_bits & SCHIZO_CEAFSR_PPIO) ?
625 "PIO" :
626 ((error_bits & SCHIZO_CEAFSR_PDRD) ?
627 "DMA Read" :
628 ((error_bits & SCHIZO_CEAFSR_PDWR) ?
629 "DMA Write" : "???")))));
630
631 /* XXX Use syndrome and afar to print out module string just like
632 * XXX UDB CE trap handler does... -DaveM
633 */
David S. Miller6c108f12007-05-07 23:49:01 -0700634 printk("%s: bytemask[%04lx] qword_offset[%lx] SAFARI_AID[%02lx]\n",
635 pbm->name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 (afsr & SCHIZO_UEAFSR_BMSK) >> 32UL,
637 (afsr & SCHIZO_UEAFSR_QOFF) >> 30UL,
638 (afsr & SCHIZO_UEAFSR_AID) >> 24UL);
David S. Miller6c108f12007-05-07 23:49:01 -0700639 printk("%s: partial[%d] owned_in[%d] mtag[%lx] mtag_synd[%lx] ecc_sync[%lx]\n",
640 pbm->name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 (afsr & SCHIZO_UEAFSR_PARTIAL) ? 1 : 0,
642 (afsr & SCHIZO_UEAFSR_OWNEDIN) ? 1 : 0,
643 (afsr & SCHIZO_UEAFSR_MTAG) >> 13UL,
644 (afsr & SCHIZO_UEAFSR_MTAGSYND) >> 16UL,
645 (afsr & SCHIZO_UEAFSR_ECCSYND) >> 0UL);
David S. Miller6c108f12007-05-07 23:49:01 -0700646 printk("%s: CE AFAR [%016lx]\n", pbm->name, afar);
647 printk("%s: CE Secondary errors [", pbm->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 reported = 0;
649 if (afsr & SCHIZO_CEAFSR_SPIO) {
650 reported++;
651 printk("(PIO)");
652 }
653 if (afsr & SCHIZO_CEAFSR_SDMA) {
654 reported++;
655 printk("(DMA)");
656 }
657 if (!reported)
658 printk("(none)");
659 printk("]\n");
660
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 return IRQ_HANDLED;
662}
663
664#define SCHIZO_PCI_AFSR 0x2010UL
665#define SCHIZO_PCI_AFAR 0x2018UL
666
667#define SCHIZO_PCIAFSR_PMA 0x8000000000000000UL /* Schizo/Tomatillo */
668#define SCHIZO_PCIAFSR_PTA 0x4000000000000000UL /* Schizo/Tomatillo */
669#define SCHIZO_PCIAFSR_PRTRY 0x2000000000000000UL /* Schizo/Tomatillo */
670#define SCHIZO_PCIAFSR_PPERR 0x1000000000000000UL /* Schizo/Tomatillo */
671#define SCHIZO_PCIAFSR_PTTO 0x0800000000000000UL /* Schizo/Tomatillo */
672#define SCHIZO_PCIAFSR_PUNUS 0x0400000000000000UL /* Schizo */
673#define SCHIZO_PCIAFSR_SMA 0x0200000000000000UL /* Schizo/Tomatillo */
674#define SCHIZO_PCIAFSR_STA 0x0100000000000000UL /* Schizo/Tomatillo */
675#define SCHIZO_PCIAFSR_SRTRY 0x0080000000000000UL /* Schizo/Tomatillo */
676#define SCHIZO_PCIAFSR_SPERR 0x0040000000000000UL /* Schizo/Tomatillo */
677#define SCHIZO_PCIAFSR_STTO 0x0020000000000000UL /* Schizo/Tomatillo */
678#define SCHIZO_PCIAFSR_SUNUS 0x0010000000000000UL /* Schizo */
679#define SCHIZO_PCIAFSR_BMSK 0x000003ff00000000UL /* Schizo/Tomatillo */
680#define SCHIZO_PCIAFSR_BLK 0x0000000080000000UL /* Schizo/Tomatillo */
681#define SCHIZO_PCIAFSR_CFG 0x0000000040000000UL /* Schizo/Tomatillo */
682#define SCHIZO_PCIAFSR_MEM 0x0000000020000000UL /* Schizo/Tomatillo */
683#define SCHIZO_PCIAFSR_IO 0x0000000010000000UL /* Schizo/Tomatillo */
684
685#define SCHIZO_PCI_CTRL (0x2000UL)
686#define SCHIZO_PCICTRL_BUS_UNUS (1UL << 63UL) /* Safari */
David S. Miller9fba62a2005-07-04 14:53:33 -0700687#define SCHIZO_PCICTRL_DTO_INT (1UL << 61UL) /* Tomatillo */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688#define SCHIZO_PCICTRL_ARB_PRIO (0x1ff << 52UL) /* Tomatillo */
689#define SCHIZO_PCICTRL_ESLCK (1UL << 51UL) /* Safari */
690#define SCHIZO_PCICTRL_ERRSLOT (7UL << 48UL) /* Safari */
691#define SCHIZO_PCICTRL_TTO_ERR (1UL << 38UL) /* Safari/Tomatillo */
692#define SCHIZO_PCICTRL_RTRY_ERR (1UL << 37UL) /* Safari/Tomatillo */
693#define SCHIZO_PCICTRL_DTO_ERR (1UL << 36UL) /* Safari/Tomatillo */
694#define SCHIZO_PCICTRL_SBH_ERR (1UL << 35UL) /* Safari */
695#define SCHIZO_PCICTRL_SERR (1UL << 34UL) /* Safari/Tomatillo */
696#define SCHIZO_PCICTRL_PCISPD (1UL << 33UL) /* Safari */
697#define SCHIZO_PCICTRL_MRM_PREF (1UL << 30UL) /* Tomatillo */
698#define SCHIZO_PCICTRL_RDO_PREF (1UL << 29UL) /* Tomatillo */
699#define SCHIZO_PCICTRL_RDL_PREF (1UL << 28UL) /* Tomatillo */
700#define SCHIZO_PCICTRL_PTO (3UL << 24UL) /* Safari/Tomatillo */
701#define SCHIZO_PCICTRL_PTO_SHIFT 24UL
702#define SCHIZO_PCICTRL_TRWSW (7UL << 21UL) /* Tomatillo */
703#define SCHIZO_PCICTRL_F_TGT_A (1UL << 20UL) /* Tomatillo */
704#define SCHIZO_PCICTRL_S_DTO_INT (1UL << 19UL) /* Safari */
705#define SCHIZO_PCICTRL_F_TGT_RT (1UL << 19UL) /* Tomatillo */
706#define SCHIZO_PCICTRL_SBH_INT (1UL << 18UL) /* Safari */
707#define SCHIZO_PCICTRL_T_DTO_INT (1UL << 18UL) /* Tomatillo */
708#define SCHIZO_PCICTRL_EEN (1UL << 17UL) /* Safari/Tomatillo */
709#define SCHIZO_PCICTRL_PARK (1UL << 16UL) /* Safari/Tomatillo */
710#define SCHIZO_PCICTRL_PCIRST (1UL << 8UL) /* Safari */
711#define SCHIZO_PCICTRL_ARB_S (0x3fUL << 0UL) /* Safari */
712#define SCHIZO_PCICTRL_ARB_T (0xffUL << 0UL) /* Tomatillo */
713
714static irqreturn_t schizo_pcierr_intr_other(struct pci_pbm_info *pbm)
715{
716 unsigned long csr_reg, csr, csr_error_bits;
717 irqreturn_t ret = IRQ_NONE;
718 u16 stat;
719
720 csr_reg = pbm->pbm_regs + SCHIZO_PCI_CTRL;
721 csr = schizo_read(csr_reg);
722 csr_error_bits =
723 csr & (SCHIZO_PCICTRL_BUS_UNUS |
724 SCHIZO_PCICTRL_TTO_ERR |
725 SCHIZO_PCICTRL_RTRY_ERR |
726 SCHIZO_PCICTRL_DTO_ERR |
727 SCHIZO_PCICTRL_SBH_ERR |
728 SCHIZO_PCICTRL_SERR);
729 if (csr_error_bits) {
730 /* Clear the errors. */
731 schizo_write(csr_reg, csr);
732
733 /* Log 'em. */
734 if (csr_error_bits & SCHIZO_PCICTRL_BUS_UNUS)
735 printk("%s: Bus unusable error asserted.\n",
736 pbm->name);
737 if (csr_error_bits & SCHIZO_PCICTRL_TTO_ERR)
738 printk("%s: PCI TRDY# timeout error asserted.\n",
739 pbm->name);
740 if (csr_error_bits & SCHIZO_PCICTRL_RTRY_ERR)
741 printk("%s: PCI excessive retry error asserted.\n",
742 pbm->name);
743 if (csr_error_bits & SCHIZO_PCICTRL_DTO_ERR)
744 printk("%s: PCI discard timeout error asserted.\n",
745 pbm->name);
746 if (csr_error_bits & SCHIZO_PCICTRL_SBH_ERR)
747 printk("%s: PCI streaming byte hole error asserted.\n",
748 pbm->name);
749 if (csr_error_bits & SCHIZO_PCICTRL_SERR)
750 printk("%s: PCI SERR signal asserted.\n",
751 pbm->name);
752 ret = IRQ_HANDLED;
753 }
754 pci_read_config_word(pbm->pci_bus->self, PCI_STATUS, &stat);
755 if (stat & (PCI_STATUS_PARITY |
756 PCI_STATUS_SIG_TARGET_ABORT |
757 PCI_STATUS_REC_TARGET_ABORT |
758 PCI_STATUS_REC_MASTER_ABORT |
759 PCI_STATUS_SIG_SYSTEM_ERROR)) {
760 printk("%s: PCI bus error, PCI_STATUS[%04x]\n",
761 pbm->name, stat);
762 pci_write_config_word(pbm->pci_bus->self, PCI_STATUS, 0xffff);
763 ret = IRQ_HANDLED;
764 }
765 return ret;
766}
767
Al Viro6d24c8d2006-10-08 08:23:28 -0400768static irqreturn_t schizo_pcierr_intr(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769{
770 struct pci_pbm_info *pbm = dev_id;
771 struct pci_controller_info *p = pbm->parent;
772 unsigned long afsr_reg, afar_reg, base;
773 unsigned long afsr, afar, error_bits;
774 int reported;
775
776 base = pbm->pbm_regs;
777
778 afsr_reg = base + SCHIZO_PCI_AFSR;
779 afar_reg = base + SCHIZO_PCI_AFAR;
780
781 /* Latch error status. */
782 afar = schizo_read(afar_reg);
783 afsr = schizo_read(afsr_reg);
784
785 /* Clear primary/secondary error status bits. */
786 error_bits = afsr &
787 (SCHIZO_PCIAFSR_PMA | SCHIZO_PCIAFSR_PTA |
788 SCHIZO_PCIAFSR_PRTRY | SCHIZO_PCIAFSR_PPERR |
789 SCHIZO_PCIAFSR_PTTO | SCHIZO_PCIAFSR_PUNUS |
790 SCHIZO_PCIAFSR_SMA | SCHIZO_PCIAFSR_STA |
791 SCHIZO_PCIAFSR_SRTRY | SCHIZO_PCIAFSR_SPERR |
792 SCHIZO_PCIAFSR_STTO | SCHIZO_PCIAFSR_SUNUS);
793 if (!error_bits)
794 return schizo_pcierr_intr_other(pbm);
795 schizo_write(afsr_reg, error_bits);
796
797 /* Log the error. */
798 printk("%s: PCI Error, primary error type[%s]\n",
799 pbm->name,
800 (((error_bits & SCHIZO_PCIAFSR_PMA) ?
801 "Master Abort" :
802 ((error_bits & SCHIZO_PCIAFSR_PTA) ?
803 "Target Abort" :
804 ((error_bits & SCHIZO_PCIAFSR_PRTRY) ?
805 "Excessive Retries" :
806 ((error_bits & SCHIZO_PCIAFSR_PPERR) ?
807 "Parity Error" :
808 ((error_bits & SCHIZO_PCIAFSR_PTTO) ?
809 "Timeout" :
810 ((error_bits & SCHIZO_PCIAFSR_PUNUS) ?
811 "Bus Unusable" : "???"))))))));
812 printk("%s: bytemask[%04lx] was_block(%d) space(%s)\n",
813 pbm->name,
814 (afsr & SCHIZO_PCIAFSR_BMSK) >> 32UL,
815 (afsr & SCHIZO_PCIAFSR_BLK) ? 1 : 0,
816 ((afsr & SCHIZO_PCIAFSR_CFG) ?
817 "Config" :
818 ((afsr & SCHIZO_PCIAFSR_MEM) ?
819 "Memory" :
820 ((afsr & SCHIZO_PCIAFSR_IO) ?
821 "I/O" : "???"))));
822 printk("%s: PCI AFAR [%016lx]\n",
823 pbm->name, afar);
824 printk("%s: PCI Secondary errors [",
825 pbm->name);
826 reported = 0;
827 if (afsr & SCHIZO_PCIAFSR_SMA) {
828 reported++;
829 printk("(Master Abort)");
830 }
831 if (afsr & SCHIZO_PCIAFSR_STA) {
832 reported++;
833 printk("(Target Abort)");
834 }
835 if (afsr & SCHIZO_PCIAFSR_SRTRY) {
836 reported++;
837 printk("(Excessive Retries)");
838 }
839 if (afsr & SCHIZO_PCIAFSR_SPERR) {
840 reported++;
841 printk("(Parity Error)");
842 }
843 if (afsr & SCHIZO_PCIAFSR_STTO) {
844 reported++;
845 printk("(Timeout)");
846 }
847 if (afsr & SCHIZO_PCIAFSR_SUNUS) {
848 reported++;
849 printk("(Bus Unusable)");
850 }
851 if (!reported)
852 printk("(none)");
853 printk("]\n");
854
855 /* For the error types shown, scan PBM's PCI bus for devices
856 * which have logged that error type.
857 */
858
859 /* If we see a Target Abort, this could be the result of an
860 * IOMMU translation error of some sort. It is extremely
861 * useful to log this information as usually it indicates
862 * a bug in the IOMMU support code or a PCI device driver.
863 */
864 if (error_bits & (SCHIZO_PCIAFSR_PTA | SCHIZO_PCIAFSR_STA)) {
865 schizo_check_iommu_error(p, PCI_ERR);
David S. Miller6c108f12007-05-07 23:49:01 -0700866 pci_scan_for_target_abort(pbm, pbm->pci_bus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 }
868 if (error_bits & (SCHIZO_PCIAFSR_PMA | SCHIZO_PCIAFSR_SMA))
David S. Miller6c108f12007-05-07 23:49:01 -0700869 pci_scan_for_master_abort(pbm, pbm->pci_bus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870
871 /* For excessive retries, PSYCHO/PBM will abort the device
872 * and there is no way to specifically check for excessive
873 * retries in the config space status registers. So what
874 * we hope is that we'll catch it via the master/target
875 * abort events.
876 */
877
878 if (error_bits & (SCHIZO_PCIAFSR_PPERR | SCHIZO_PCIAFSR_SPERR))
David S. Miller6c108f12007-05-07 23:49:01 -0700879 pci_scan_for_parity_error(pbm, pbm->pci_bus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 return IRQ_HANDLED;
882}
883
884#define SCHIZO_SAFARI_ERRLOG 0x10018UL
885
886#define SAFARI_ERRLOG_ERROUT 0x8000000000000000UL
887
888#define BUS_ERROR_BADCMD 0x4000000000000000UL /* Schizo/Tomatillo */
889#define BUS_ERROR_SSMDIS 0x2000000000000000UL /* Safari */
890#define BUS_ERROR_BADMA 0x1000000000000000UL /* Safari */
891#define BUS_ERROR_BADMB 0x0800000000000000UL /* Safari */
892#define BUS_ERROR_BADMC 0x0400000000000000UL /* Safari */
893#define BUS_ERROR_SNOOP_GR 0x0000000000200000UL /* Tomatillo */
894#define BUS_ERROR_SNOOP_PCI 0x0000000000100000UL /* Tomatillo */
895#define BUS_ERROR_SNOOP_RD 0x0000000000080000UL /* Tomatillo */
896#define BUS_ERROR_SNOOP_RDS 0x0000000000020000UL /* Tomatillo */
897#define BUS_ERROR_SNOOP_RDSA 0x0000000000010000UL /* Tomatillo */
898#define BUS_ERROR_SNOOP_OWN 0x0000000000008000UL /* Tomatillo */
899#define BUS_ERROR_SNOOP_RDO 0x0000000000004000UL /* Tomatillo */
900#define BUS_ERROR_CPU1PS 0x0000000000002000UL /* Safari */
901#define BUS_ERROR_WDATA_PERR 0x0000000000002000UL /* Tomatillo */
902#define BUS_ERROR_CPU1PB 0x0000000000001000UL /* Safari */
903#define BUS_ERROR_CTRL_PERR 0x0000000000001000UL /* Tomatillo */
904#define BUS_ERROR_CPU0PS 0x0000000000000800UL /* Safari */
905#define BUS_ERROR_SNOOP_ERR 0x0000000000000800UL /* Tomatillo */
906#define BUS_ERROR_CPU0PB 0x0000000000000400UL /* Safari */
907#define BUS_ERROR_JBUS_ILL_B 0x0000000000000400UL /* Tomatillo */
908#define BUS_ERROR_CIQTO 0x0000000000000200UL /* Safari */
909#define BUS_ERROR_LPQTO 0x0000000000000100UL /* Safari */
910#define BUS_ERROR_JBUS_ILL_C 0x0000000000000100UL /* Tomatillo */
911#define BUS_ERROR_SFPQTO 0x0000000000000080UL /* Safari */
912#define BUS_ERROR_UFPQTO 0x0000000000000040UL /* Safari */
913#define BUS_ERROR_RD_PERR 0x0000000000000040UL /* Tomatillo */
914#define BUS_ERROR_APERR 0x0000000000000020UL /* Safari/Tomatillo */
915#define BUS_ERROR_UNMAP 0x0000000000000010UL /* Safari/Tomatillo */
916#define BUS_ERROR_BUSERR 0x0000000000000004UL /* Safari/Tomatillo */
917#define BUS_ERROR_TIMEOUT 0x0000000000000002UL /* Safari/Tomatillo */
918#define BUS_ERROR_ILL 0x0000000000000001UL /* Safari */
919
920/* We only expect UNMAP errors here. The rest of the Safari errors
921 * are marked fatal and thus cause a system reset.
922 */
Al Viro6d24c8d2006-10-08 08:23:28 -0400923static irqreturn_t schizo_safarierr_intr(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924{
David S. Miller34768bc2007-05-07 23:06:27 -0700925 struct pci_pbm_info *pbm = dev_id;
926 struct pci_controller_info *p = pbm->parent;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 u64 errlog;
928
David S. Miller34768bc2007-05-07 23:06:27 -0700929 errlog = schizo_read(pbm->controller_regs + SCHIZO_SAFARI_ERRLOG);
930 schizo_write(pbm->controller_regs + SCHIZO_SAFARI_ERRLOG,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 errlog & ~(SAFARI_ERRLOG_ERROUT));
932
933 if (!(errlog & BUS_ERROR_UNMAP)) {
David S. Miller6c108f12007-05-07 23:49:01 -0700934 printk("%s: Unexpected Safari/JBUS error interrupt, errlog[%016lx]\n",
935 pbm->name, errlog);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 return IRQ_HANDLED;
938 }
939
David S. Miller6c108f12007-05-07 23:49:01 -0700940 printk("%s: Safari/JBUS interrupt, UNMAPPED error, interrogating IOMMUs.\n",
941 pbm->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 schizo_check_iommu_error(p, SAFARI_ERR);
943
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 return IRQ_HANDLED;
945}
946
947/* Nearly identical to PSYCHO equivalents... */
948#define SCHIZO_ECC_CTRL 0x10020UL
949#define SCHIZO_ECCCTRL_EE 0x8000000000000000UL /* Enable ECC Checking */
950#define SCHIZO_ECCCTRL_UE 0x4000000000000000UL /* Enable UE Interrupts */
951#define SCHIZO_ECCCTRL_CE 0x2000000000000000UL /* Enable CE INterrupts */
952
953#define SCHIZO_SAFARI_ERRCTRL 0x10008UL
954#define SCHIZO_SAFERRCTRL_EN 0x8000000000000000UL
955#define SCHIZO_SAFARI_IRQCTRL 0x10010UL
956#define SCHIZO_SAFIRQCTRL_EN 0x8000000000000000UL
957
David S. Miller34768bc2007-05-07 23:06:27 -0700958static int pbm_routes_this_ino(struct pci_pbm_info *pbm, u32 ino)
959{
960 ino &= IMAP_INO;
961
962 if (pbm->ino_bitmap & (1UL << ino))
963 return 1;
964
965 return 0;
966}
967
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968/* How the Tomatillo IRQs are routed around is pure guesswork here.
969 *
970 * All the Tomatillo devices I see in prtconf dumps seem to have only
971 * a single PCI bus unit attached to it. It would seem they are seperate
972 * devices because their PortID (ie. JBUS ID) values are all different
973 * and thus the registers are mapped to totally different locations.
974 *
975 * However, two Tomatillo's look "similar" in that the only difference
976 * in their PortID is the lowest bit.
977 *
978 * So if we were to ignore this lower bit, it certainly looks like two
979 * PCI bus units of the same Tomatillo. I still have not really
980 * figured this out...
981 */
David S. Miller34768bc2007-05-07 23:06:27 -0700982static void tomatillo_register_error_handlers(struct pci_pbm_info *pbm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983{
David S. Miller34768bc2007-05-07 23:06:27 -0700984 struct of_device *op = of_find_device_by_node(pbm->prom_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 u64 tmp, err_mask, err_no_mask;
986
David S. Miller2b1e5972006-06-29 15:07:37 -0700987 /* Tomatillo IRQ property layout is:
988 * 0: PCIERR
989 * 1: UE ERR
990 * 2: CE ERR
991 * 3: SERR
992 * 4: POWER FAIL?
993 */
994
David S. Miller34768bc2007-05-07 23:06:27 -0700995 if (pbm_routes_this_ino(pbm, SCHIZO_UE_INO))
996 request_irq(op->irqs[1], schizo_ue_intr, 0,
997 "TOMATILLO_UE", pbm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998
David S. Miller34768bc2007-05-07 23:06:27 -0700999 if (pbm_routes_this_ino(pbm, SCHIZO_CE_INO))
1000 request_irq(op->irqs[2], schizo_ce_intr, 0,
1001 "TOMATILLO_CE", pbm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002
David S. Miller34768bc2007-05-07 23:06:27 -07001003 if (pbm_routes_this_ino(pbm, SCHIZO_PCIERR_A_INO))
1004 request_irq(op->irqs[0], schizo_pcierr_intr, 0,
1005 "TOMATILLO_PCIERR", pbm);
1006 else if (pbm_routes_this_ino(pbm, SCHIZO_PCIERR_B_INO))
1007 request_irq(op->irqs[0], schizo_pcierr_intr, 0,
1008 "TOMATILLO_PCIERR", pbm);
David S. Miller2b1e5972006-06-29 15:07:37 -07001009
David S. Miller34768bc2007-05-07 23:06:27 -07001010 if (pbm_routes_this_ino(pbm, SCHIZO_SERR_INO))
1011 request_irq(op->irqs[3], schizo_safarierr_intr, 0,
1012 "TOMATILLO_SERR", pbm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013
1014 /* Enable UE and CE interrupts for controller. */
David S. Miller34768bc2007-05-07 23:06:27 -07001015 schizo_write(pbm->controller_regs + SCHIZO_ECC_CTRL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 (SCHIZO_ECCCTRL_EE |
1017 SCHIZO_ECCCTRL_UE |
1018 SCHIZO_ECCCTRL_CE));
1019
1020 /* Enable PCI Error interrupts and clear error
1021 * bits.
1022 */
1023 err_mask = (SCHIZO_PCICTRL_BUS_UNUS |
1024 SCHIZO_PCICTRL_TTO_ERR |
1025 SCHIZO_PCICTRL_RTRY_ERR |
1026 SCHIZO_PCICTRL_SERR |
1027 SCHIZO_PCICTRL_EEN);
1028
1029 err_no_mask = SCHIZO_PCICTRL_DTO_ERR;
1030
David S. Miller34768bc2007-05-07 23:06:27 -07001031 tmp = schizo_read(pbm->pbm_regs + SCHIZO_PCI_CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 tmp |= err_mask;
1033 tmp &= ~err_no_mask;
David S. Miller34768bc2007-05-07 23:06:27 -07001034 schizo_write(pbm->pbm_regs + SCHIZO_PCI_CTRL, tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035
1036 err_mask = (SCHIZO_PCIAFSR_PMA | SCHIZO_PCIAFSR_PTA |
1037 SCHIZO_PCIAFSR_PRTRY | SCHIZO_PCIAFSR_PPERR |
1038 SCHIZO_PCIAFSR_PTTO |
1039 SCHIZO_PCIAFSR_SMA | SCHIZO_PCIAFSR_STA |
1040 SCHIZO_PCIAFSR_SRTRY | SCHIZO_PCIAFSR_SPERR |
1041 SCHIZO_PCIAFSR_STTO);
1042
David S. Miller34768bc2007-05-07 23:06:27 -07001043 schizo_write(pbm->pbm_regs + SCHIZO_PCI_AFSR, err_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044
1045 err_mask = (BUS_ERROR_BADCMD | BUS_ERROR_SNOOP_GR |
1046 BUS_ERROR_SNOOP_PCI | BUS_ERROR_SNOOP_RD |
1047 BUS_ERROR_SNOOP_RDS | BUS_ERROR_SNOOP_RDSA |
1048 BUS_ERROR_SNOOP_OWN | BUS_ERROR_SNOOP_RDO |
1049 BUS_ERROR_WDATA_PERR | BUS_ERROR_CTRL_PERR |
1050 BUS_ERROR_SNOOP_ERR | BUS_ERROR_JBUS_ILL_B |
1051 BUS_ERROR_JBUS_ILL_C | BUS_ERROR_RD_PERR |
1052 BUS_ERROR_APERR | BUS_ERROR_UNMAP |
1053 BUS_ERROR_BUSERR | BUS_ERROR_TIMEOUT);
1054
David S. Miller34768bc2007-05-07 23:06:27 -07001055 schizo_write(pbm->controller_regs + SCHIZO_SAFARI_ERRCTRL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 (SCHIZO_SAFERRCTRL_EN | err_mask));
1057
David S. Miller34768bc2007-05-07 23:06:27 -07001058 schizo_write(pbm->controller_regs + SCHIZO_SAFARI_IRQCTRL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 (SCHIZO_SAFIRQCTRL_EN | (BUS_ERROR_UNMAP)));
1060}
1061
David S. Miller34768bc2007-05-07 23:06:27 -07001062static void schizo_register_error_handlers(struct pci_pbm_info *pbm)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063{
David S. Miller34768bc2007-05-07 23:06:27 -07001064 struct of_device *op = of_find_device_by_node(pbm->prom_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 u64 tmp, err_mask, err_no_mask;
1066
David S. Miller2b1e5972006-06-29 15:07:37 -07001067 /* Schizo IRQ property layout is:
1068 * 0: PCIERR
1069 * 1: UE ERR
1070 * 2: CE ERR
1071 * 3: SERR
1072 * 4: POWER FAIL?
1073 */
1074
David S. Miller34768bc2007-05-07 23:06:27 -07001075 if (pbm_routes_this_ino(pbm, SCHIZO_UE_INO))
1076 request_irq(op->irqs[1], schizo_ue_intr, 0,
1077 "SCHIZO_UE", pbm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078
David S. Miller34768bc2007-05-07 23:06:27 -07001079 if (pbm_routes_this_ino(pbm, SCHIZO_CE_INO))
1080 request_irq(op->irqs[2], schizo_ce_intr, 0,
1081 "SCHIZO_CE", pbm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082
David S. Miller34768bc2007-05-07 23:06:27 -07001083 if (pbm_routes_this_ino(pbm, SCHIZO_PCIERR_A_INO))
1084 request_irq(op->irqs[0], schizo_pcierr_intr, 0,
1085 "SCHIZO_PCIERR", pbm);
1086 else if (pbm_routes_this_ino(pbm, SCHIZO_PCIERR_B_INO))
1087 request_irq(op->irqs[0], schizo_pcierr_intr, 0,
1088 "SCHIZO_PCIERR", pbm);
David S. Miller2b1e5972006-06-29 15:07:37 -07001089
David S. Miller34768bc2007-05-07 23:06:27 -07001090 if (pbm_routes_this_ino(pbm, SCHIZO_SERR_INO))
1091 request_irq(op->irqs[3], schizo_safarierr_intr, 0,
1092 "SCHIZO_SERR", pbm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093
1094 /* Enable UE and CE interrupts for controller. */
David S. Miller34768bc2007-05-07 23:06:27 -07001095 schizo_write(pbm->controller_regs + SCHIZO_ECC_CTRL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 (SCHIZO_ECCCTRL_EE |
1097 SCHIZO_ECCCTRL_UE |
1098 SCHIZO_ECCCTRL_CE));
1099
1100 err_mask = (SCHIZO_PCICTRL_BUS_UNUS |
1101 SCHIZO_PCICTRL_ESLCK |
1102 SCHIZO_PCICTRL_TTO_ERR |
1103 SCHIZO_PCICTRL_RTRY_ERR |
1104 SCHIZO_PCICTRL_SBH_ERR |
1105 SCHIZO_PCICTRL_SERR |
1106 SCHIZO_PCICTRL_EEN);
1107
1108 err_no_mask = (SCHIZO_PCICTRL_DTO_ERR |
1109 SCHIZO_PCICTRL_SBH_INT);
1110
1111 /* Enable PCI Error interrupts and clear error
1112 * bits for each PBM.
1113 */
David S. Miller34768bc2007-05-07 23:06:27 -07001114 tmp = schizo_read(pbm->pbm_regs + SCHIZO_PCI_CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 tmp |= err_mask;
1116 tmp &= ~err_no_mask;
David S. Miller34768bc2007-05-07 23:06:27 -07001117 schizo_write(pbm->pbm_regs + SCHIZO_PCI_CTRL, tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118
David S. Miller34768bc2007-05-07 23:06:27 -07001119 schizo_write(pbm->pbm_regs + SCHIZO_PCI_AFSR,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 (SCHIZO_PCIAFSR_PMA | SCHIZO_PCIAFSR_PTA |
1121 SCHIZO_PCIAFSR_PRTRY | SCHIZO_PCIAFSR_PPERR |
1122 SCHIZO_PCIAFSR_PTTO | SCHIZO_PCIAFSR_PUNUS |
1123 SCHIZO_PCIAFSR_SMA | SCHIZO_PCIAFSR_STA |
1124 SCHIZO_PCIAFSR_SRTRY | SCHIZO_PCIAFSR_SPERR |
1125 SCHIZO_PCIAFSR_STTO | SCHIZO_PCIAFSR_SUNUS));
1126
1127 /* Make all Safari error conditions fatal except unmapped
1128 * errors which we make generate interrupts.
1129 */
1130 err_mask = (BUS_ERROR_BADCMD | BUS_ERROR_SSMDIS |
1131 BUS_ERROR_BADMA | BUS_ERROR_BADMB |
1132 BUS_ERROR_BADMC |
1133 BUS_ERROR_CPU1PS | BUS_ERROR_CPU1PB |
1134 BUS_ERROR_CPU0PS | BUS_ERROR_CPU0PB |
1135 BUS_ERROR_CIQTO |
1136 BUS_ERROR_LPQTO | BUS_ERROR_SFPQTO |
1137 BUS_ERROR_UFPQTO | BUS_ERROR_APERR |
1138 BUS_ERROR_BUSERR | BUS_ERROR_TIMEOUT |
1139 BUS_ERROR_ILL);
1140#if 1
1141 /* XXX Something wrong with some Excalibur systems
1142 * XXX Sun is shipping. The behavior on a 2-cpu
1143 * XXX machine is that both CPU1 parity error bits
1144 * XXX are set and are immediately set again when
1145 * XXX their error status bits are cleared. Just
1146 * XXX ignore them for now. -DaveM
1147 */
1148 err_mask &= ~(BUS_ERROR_CPU1PS | BUS_ERROR_CPU1PB |
1149 BUS_ERROR_CPU0PS | BUS_ERROR_CPU0PB);
1150#endif
1151
David S. Miller34768bc2007-05-07 23:06:27 -07001152 schizo_write(pbm->controller_regs + SCHIZO_SAFARI_ERRCTRL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 (SCHIZO_SAFERRCTRL_EN | err_mask));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154}
1155
David S. Miller085ae412005-08-08 13:19:08 -07001156static void pbm_config_busmastering(struct pci_pbm_info *pbm)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157{
1158 u8 *addr;
1159
1160 /* Set cache-line size to 64 bytes, this is actually
1161 * a nop but I do it for completeness.
1162 */
1163 addr = schizo_pci_config_mkaddr(pbm, pbm->pci_first_busno,
1164 0, PCI_CACHE_LINE_SIZE);
1165 pci_config_write8(addr, 64 / sizeof(u32));
1166
1167 /* Set PBM latency timer to 64 PCI clocks. */
1168 addr = schizo_pci_config_mkaddr(pbm, pbm->pci_first_busno,
1169 0, PCI_LATENCY_TIMER);
1170 pci_config_write8(addr, 64);
1171}
1172
David S. Miller34768bc2007-05-07 23:06:27 -07001173static void schizo_scan_bus(struct pci_pbm_info *pbm)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174{
David S. Miller34768bc2007-05-07 23:06:27 -07001175 pbm_config_busmastering(pbm);
1176 pbm->is_66mhz_capable =
1177 (of_find_property(pbm->prom_node, "66mhz-capable", NULL)
David S. Millere87dc352006-06-21 18:18:47 -07001178 != NULL);
David S. Millerbc606f32007-03-01 11:20:37 -08001179
David S. Miller34768bc2007-05-07 23:06:27 -07001180 pbm->pci_bus = pci_scan_one_pbm(pbm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181
David S. Miller34768bc2007-05-07 23:06:27 -07001182 if (pbm->chip_type == PBM_CHIP_TYPE_TOMATILLO)
1183 tomatillo_register_error_handlers(pbm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 else
David S. Miller34768bc2007-05-07 23:06:27 -07001185 schizo_register_error_handlers(pbm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186}
1187
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188#define SCHIZO_STRBUF_CONTROL (0x02800UL)
1189#define SCHIZO_STRBUF_FLUSH (0x02808UL)
1190#define SCHIZO_STRBUF_FSYNC (0x02810UL)
1191#define SCHIZO_STRBUF_CTXFLUSH (0x02818UL)
1192#define SCHIZO_STRBUF_CTXMATCH (0x10000UL)
1193
1194static void schizo_pbm_strbuf_init(struct pci_pbm_info *pbm)
1195{
1196 unsigned long base = pbm->pbm_regs;
1197 u64 control;
1198
1199 if (pbm->chip_type == PBM_CHIP_TYPE_TOMATILLO) {
1200 /* TOMATILLO lacks streaming cache. */
1201 return;
1202 }
1203
1204 /* SCHIZO has context flushing. */
1205 pbm->stc.strbuf_control = base + SCHIZO_STRBUF_CONTROL;
1206 pbm->stc.strbuf_pflush = base + SCHIZO_STRBUF_FLUSH;
1207 pbm->stc.strbuf_fsync = base + SCHIZO_STRBUF_FSYNC;
1208 pbm->stc.strbuf_ctxflush = base + SCHIZO_STRBUF_CTXFLUSH;
1209 pbm->stc.strbuf_ctxmatch_base = base + SCHIZO_STRBUF_CTXMATCH;
1210
1211 pbm->stc.strbuf_flushflag = (volatile unsigned long *)
1212 ((((unsigned long)&pbm->stc.__flushflag_buf[0])
1213 + 63UL)
1214 & ~63UL);
1215 pbm->stc.strbuf_flushflag_pa = (unsigned long)
1216 __pa(pbm->stc.strbuf_flushflag);
1217
1218 /* Turn off LRU locking and diag mode, enable the
1219 * streaming buffer and leave the rerun-disable
1220 * setting however OBP set it.
1221 */
1222 control = schizo_read(pbm->stc.strbuf_control);
1223 control &= ~(SCHIZO_STRBUF_CTRL_LPTR |
1224 SCHIZO_STRBUF_CTRL_LENAB |
1225 SCHIZO_STRBUF_CTRL_DENAB);
1226 control |= SCHIZO_STRBUF_CTRL_ENAB;
1227 schizo_write(pbm->stc.strbuf_control, control);
1228
1229 pbm->stc.strbuf_enabled = 1;
1230}
1231
1232#define SCHIZO_IOMMU_CONTROL (0x00200UL)
1233#define SCHIZO_IOMMU_TSBBASE (0x00208UL)
1234#define SCHIZO_IOMMU_FLUSH (0x00210UL)
1235#define SCHIZO_IOMMU_CTXFLUSH (0x00218UL)
1236
1237static void schizo_pbm_iommu_init(struct pci_pbm_info *pbm)
1238{
David S. Miller16ce82d2007-04-26 21:08:21 -07001239 struct iommu *iommu = pbm->iommu;
David S. Miller51e85132005-10-13 21:10:08 -07001240 unsigned long i, tagbase, database;
David S. Millere87dc352006-06-21 18:18:47 -07001241 struct property *prop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242 u32 vdma[2], dma_mask;
1243 u64 control;
David S. Millere87dc352006-06-21 18:18:47 -07001244 int tsbsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245
David S. Millere87dc352006-06-21 18:18:47 -07001246 prop = of_find_property(pbm->prom_node, "virtual-dma", NULL);
1247 if (prop) {
1248 u32 *val = prop->value;
1249
1250 vdma[0] = val[0];
1251 vdma[1] = val[1];
1252 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 /* No property, use default values. */
1254 vdma[0] = 0xc0000000;
1255 vdma[1] = 0x40000000;
1256 }
1257
1258 dma_mask = vdma[0];
1259 switch (vdma[1]) {
1260 case 0x20000000:
1261 dma_mask |= 0x1fffffff;
1262 tsbsize = 64;
1263 break;
1264
1265 case 0x40000000:
1266 dma_mask |= 0x3fffffff;
1267 tsbsize = 128;
1268 break;
1269
1270 case 0x80000000:
1271 dma_mask |= 0x7fffffff;
1272 tsbsize = 128;
1273 break;
1274
1275 default:
1276 prom_printf("SCHIZO: strange virtual-dma size.\n");
1277 prom_halt();
1278 };
1279
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280 /* Register addresses, SCHIZO has iommu ctx flushing. */
1281 iommu->iommu_control = pbm->pbm_regs + SCHIZO_IOMMU_CONTROL;
1282 iommu->iommu_tsbbase = pbm->pbm_regs + SCHIZO_IOMMU_TSBBASE;
1283 iommu->iommu_flush = pbm->pbm_regs + SCHIZO_IOMMU_FLUSH;
1284 iommu->iommu_ctxflush = pbm->pbm_regs + SCHIZO_IOMMU_CTXFLUSH;
1285
1286 /* We use the main control/status register of SCHIZO as the write
1287 * completion register.
1288 */
1289 iommu->write_complete_reg = pbm->controller_regs + 0x10000UL;
1290
1291 /*
1292 * Invalidate TLB Entries.
1293 */
1294 control = schizo_read(iommu->iommu_control);
1295 control |= SCHIZO_IOMMU_CTRL_DENAB;
1296 schizo_write(iommu->iommu_control, control);
1297
1298 tagbase = SCHIZO_IOMMU_TAG, database = SCHIZO_IOMMU_DATA;
1299
1300 for(i = 0; i < 16; i++) {
1301 schizo_write(pbm->pbm_regs + tagbase + (i * 8UL), 0);
1302 schizo_write(pbm->pbm_regs + database + (i * 8UL), 0);
1303 }
1304
1305 /* Leave diag mode enabled for full-flushing done
1306 * in pci_iommu.c
1307 */
David S. Miller51e85132005-10-13 21:10:08 -07001308 pci_iommu_table_init(iommu, tsbsize * 8 * 1024, vdma[0], dma_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309
David S. Miller51e85132005-10-13 21:10:08 -07001310 schizo_write(iommu->iommu_tsbbase, __pa(iommu->page_table));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311
1312 control = schizo_read(iommu->iommu_control);
1313 control &= ~(SCHIZO_IOMMU_CTRL_TSBSZ | SCHIZO_IOMMU_CTRL_TBWSZ);
1314 switch (tsbsize) {
1315 case 64:
1316 control |= SCHIZO_IOMMU_TSBSZ_64K;
1317 break;
1318 case 128:
1319 control |= SCHIZO_IOMMU_TSBSZ_128K;
1320 break;
1321 };
1322
1323 control |= SCHIZO_IOMMU_CTRL_ENAB;
1324 schizo_write(iommu->iommu_control, control);
1325}
1326
1327#define SCHIZO_PCI_IRQ_RETRY (0x1a00UL)
1328#define SCHIZO_IRQ_RETRY_INF 0xffUL
1329
1330#define SCHIZO_PCI_DIAG (0x2020UL)
1331#define SCHIZO_PCIDIAG_D_BADECC (1UL << 10UL) /* Disable BAD ECC errors (Schizo) */
1332#define SCHIZO_PCIDIAG_D_BYPASS (1UL << 9UL) /* Disable MMU bypass mode (Schizo/Tomatillo) */
1333#define SCHIZO_PCIDIAG_D_TTO (1UL << 8UL) /* Disable TTO errors (Schizo/Tomatillo) */
1334#define SCHIZO_PCIDIAG_D_RTRYARB (1UL << 7UL) /* Disable retry arbitration (Schizo) */
1335#define SCHIZO_PCIDIAG_D_RETRY (1UL << 6UL) /* Disable retry limit (Schizo/Tomatillo) */
1336#define SCHIZO_PCIDIAG_D_INTSYNC (1UL << 5UL) /* Disable interrupt/DMA synch (Schizo/Tomatillo) */
1337#define SCHIZO_PCIDIAG_I_DMA_PARITY (1UL << 3UL) /* Invert DMA parity (Schizo/Tomatillo) */
1338#define SCHIZO_PCIDIAG_I_PIOD_PARITY (1UL << 2UL) /* Invert PIO data parity (Schizo/Tomatillo) */
1339#define SCHIZO_PCIDIAG_I_PIOA_PARITY (1UL << 1UL) /* Invert PIO address parity (Schizo/Tomatillo) */
1340
1341#define TOMATILLO_PCI_IOC_CSR (0x2248UL)
1342#define TOMATILLO_IOC_PART_WPENAB 0x0000000000080000UL
1343#define TOMATILLO_IOC_RDMULT_PENAB 0x0000000000040000UL
1344#define TOMATILLO_IOC_RDONE_PENAB 0x0000000000020000UL
1345#define TOMATILLO_IOC_RDLINE_PENAB 0x0000000000010000UL
1346#define TOMATILLO_IOC_RDMULT_PLEN 0x000000000000c000UL
1347#define TOMATILLO_IOC_RDMULT_PLEN_SHIFT 14UL
1348#define TOMATILLO_IOC_RDONE_PLEN 0x0000000000003000UL
1349#define TOMATILLO_IOC_RDONE_PLEN_SHIFT 12UL
1350#define TOMATILLO_IOC_RDLINE_PLEN 0x0000000000000c00UL
1351#define TOMATILLO_IOC_RDLINE_PLEN_SHIFT 10UL
1352#define TOMATILLO_IOC_PREF_OFF 0x00000000000003f8UL
1353#define TOMATILLO_IOC_PREF_OFF_SHIFT 3UL
1354#define TOMATILLO_IOC_RDMULT_CPENAB 0x0000000000000004UL
1355#define TOMATILLO_IOC_RDONE_CPENAB 0x0000000000000002UL
1356#define TOMATILLO_IOC_RDLINE_CPENAB 0x0000000000000001UL
1357
1358#define TOMATILLO_PCI_IOC_TDIAG (0x2250UL)
1359#define TOMATILLO_PCI_IOC_DDIAG (0x2290UL)
1360
David S. Miller085ae412005-08-08 13:19:08 -07001361static void schizo_pbm_hw_init(struct pci_pbm_info *pbm)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362{
David S. Millere87dc352006-06-21 18:18:47 -07001363 struct property *prop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 u64 tmp;
1365
David S. Miller864ae182005-07-04 15:58:19 -07001366 schizo_write(pbm->pbm_regs + SCHIZO_PCI_IRQ_RETRY, 5);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 tmp = schizo_read(pbm->pbm_regs + SCHIZO_PCI_CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369
David S. Miller9fba62a2005-07-04 14:53:33 -07001370 /* Enable arbiter for all PCI slots. */
1371 tmp |= 0xff;
1372
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 if (pbm->chip_type == PBM_CHIP_TYPE_TOMATILLO &&
1374 pbm->chip_version >= 0x2)
1375 tmp |= 0x3UL << SCHIZO_PCICTRL_PTO_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376
David S. Millere87dc352006-06-21 18:18:47 -07001377 prop = of_find_property(pbm->prom_node, "no-bus-parking", NULL);
1378 if (!prop)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 tmp |= SCHIZO_PCICTRL_PARK;
David S. Miller9fba62a2005-07-04 14:53:33 -07001380 else
1381 tmp &= ~SCHIZO_PCICTRL_PARK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382
1383 if (pbm->chip_type == PBM_CHIP_TYPE_TOMATILLO &&
1384 pbm->chip_version <= 0x1)
David S. Miller9fba62a2005-07-04 14:53:33 -07001385 tmp |= SCHIZO_PCICTRL_DTO_INT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 else
David S. Miller9fba62a2005-07-04 14:53:33 -07001387 tmp &= ~SCHIZO_PCICTRL_DTO_INT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388
1389 if (pbm->chip_type == PBM_CHIP_TYPE_TOMATILLO)
1390 tmp |= (SCHIZO_PCICTRL_MRM_PREF |
1391 SCHIZO_PCICTRL_RDO_PREF |
1392 SCHIZO_PCICTRL_RDL_PREF);
1393
1394 schizo_write(pbm->pbm_regs + SCHIZO_PCI_CTRL, tmp);
1395
1396 tmp = schizo_read(pbm->pbm_regs + SCHIZO_PCI_DIAG);
1397 tmp &= ~(SCHIZO_PCIDIAG_D_RTRYARB |
1398 SCHIZO_PCIDIAG_D_RETRY |
1399 SCHIZO_PCIDIAG_D_INTSYNC);
1400 schizo_write(pbm->pbm_regs + SCHIZO_PCI_DIAG, tmp);
1401
1402 if (pbm->chip_type == PBM_CHIP_TYPE_TOMATILLO) {
1403 /* Clear prefetch lengths to workaround a bug in
1404 * Jalapeno...
1405 */
1406 tmp = (TOMATILLO_IOC_PART_WPENAB |
1407 (1 << TOMATILLO_IOC_PREF_OFF_SHIFT) |
1408 TOMATILLO_IOC_RDMULT_CPENAB |
1409 TOMATILLO_IOC_RDONE_CPENAB |
1410 TOMATILLO_IOC_RDLINE_CPENAB);
1411
1412 schizo_write(pbm->pbm_regs + TOMATILLO_PCI_IOC_CSR,
1413 tmp);
1414 }
1415}
1416
David S. Miller085ae412005-08-08 13:19:08 -07001417static void schizo_pbm_init(struct pci_controller_info *p,
David S. Millere87dc352006-06-21 18:18:47 -07001418 struct device_node *dp, u32 portid,
David S. Miller085ae412005-08-08 13:19:08 -07001419 int chip_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420{
David S. Millera165b422007-03-29 01:50:16 -07001421 const struct linux_prom64_registers *regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 struct pci_pbm_info *pbm;
1423 const char *chipset_name;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 int is_pbm_a;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425
1426 switch (chip_type) {
1427 case PBM_CHIP_TYPE_TOMATILLO:
1428 chipset_name = "TOMATILLO";
1429 break;
1430
1431 case PBM_CHIP_TYPE_SCHIZO_PLUS:
1432 chipset_name = "SCHIZO+";
1433 break;
1434
1435 case PBM_CHIP_TYPE_SCHIZO:
1436 default:
1437 chipset_name = "SCHIZO";
1438 break;
1439 };
1440
1441 /* For SCHIZO, three OBP regs:
1442 * 1) PBM controller regs
1443 * 2) Schizo front-end controller regs (same for both PBMs)
1444 * 3) PBM PCI config space
1445 *
1446 * For TOMATILLO, four OBP regs:
1447 * 1) PBM controller regs
1448 * 2) Tomatillo front-end controller regs
1449 * 3) PBM PCI config space
1450 * 4) Ichip regs
1451 */
David S. Millerbc606f32007-03-01 11:20:37 -08001452 regs = of_get_property(dp, "reg", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453
David S. Millere87dc352006-06-21 18:18:47 -07001454 is_pbm_a = ((regs[0].phys_addr & 0x00700000) == 0x00600000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 if (is_pbm_a)
1456 pbm = &p->pbm_A;
1457 else
1458 pbm = &p->pbm_B;
1459
David S. Miller34768bc2007-05-07 23:06:27 -07001460 pbm->next = pci_pbm_root;
1461 pci_pbm_root = pbm;
1462
1463 pbm->scan_bus = schizo_scan_bus;
David S. Millerf1cd8de2007-05-07 23:24:05 -07001464 pbm->pci_ops = &schizo_ops;
David S. Miller34768bc2007-05-07 23:06:27 -07001465
David S. Miller6c108f12007-05-07 23:49:01 -07001466 pbm->index = pci_num_pbms++;
1467
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 pbm->portid = portid;
1469 pbm->parent = p;
David S. Millere87dc352006-06-21 18:18:47 -07001470 pbm->prom_node = dp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471
1472 pbm->chip_type = chip_type;
David S. Millerbc606f32007-03-01 11:20:37 -08001473 pbm->chip_version = of_getintprop_default(dp, "version#", 0);
1474 pbm->chip_revision = of_getintprop_default(dp, "module-version#", 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475
David S. Millere87dc352006-06-21 18:18:47 -07001476 pbm->pbm_regs = regs[0].phys_addr;
1477 pbm->controller_regs = regs[1].phys_addr - 0x10000UL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478
David S. Millerbb6743f2005-07-04 13:26:04 -07001479 if (chip_type == PBM_CHIP_TYPE_TOMATILLO)
David S. Millere87dc352006-06-21 18:18:47 -07001480 pbm->sync_reg = regs[3].phys_addr + 0x1a18UL;
David S. Millerbb6743f2005-07-04 13:26:04 -07001481
David S. Millere87dc352006-06-21 18:18:47 -07001482 pbm->name = dp->full_name;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483
David S. Millere87dc352006-06-21 18:18:47 -07001484 printk("%s: %s PCI Bus Module ver[%x:%x]\n",
David S. Millerbc606f32007-03-01 11:20:37 -08001485 pbm->name, chipset_name,
David S. Millere87dc352006-06-21 18:18:47 -07001486 pbm->chip_version, pbm->chip_revision);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487
1488 schizo_pbm_hw_init(pbm);
1489
David S. Miller9fd8b642007-03-08 21:55:49 -08001490 pci_determine_mem_io_space(pbm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491
David S. Millercfa06522007-05-07 21:51:41 -07001492 pci_get_pbm_props(pbm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493
1494 schizo_pbm_iommu_init(pbm);
1495 schizo_pbm_strbuf_init(pbm);
1496}
1497
1498static inline int portid_compare(u32 x, u32 y, int chip_type)
1499{
1500 if (chip_type == PBM_CHIP_TYPE_TOMATILLO) {
1501 if (x == (y ^ 1))
1502 return 1;
1503 return 0;
1504 }
1505 return (x == y);
1506}
1507
David S. Millere87dc352006-06-21 18:18:47 -07001508static void __schizo_init(struct device_node *dp, char *model_name, int chip_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509{
1510 struct pci_controller_info *p;
David S. Miller34768bc2007-05-07 23:06:27 -07001511 struct pci_pbm_info *pbm;
David S. Miller16ce82d2007-04-26 21:08:21 -07001512 struct iommu *iommu;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513 u32 portid;
1514
David S. Millerbc606f32007-03-01 11:20:37 -08001515 portid = of_getintprop_default(dp, "portid", 0xff);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516
David S. Miller34768bc2007-05-07 23:06:27 -07001517 for (pbm = pci_pbm_root; pbm; pbm = pbm->next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518 if (portid_compare(pbm->portid, portid, chip_type)) {
David S. Miller34768bc2007-05-07 23:06:27 -07001519 schizo_pbm_init(pbm->parent, dp, portid, chip_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520 return;
1521 }
1522 }
1523
Eric Sesterhenn91329832006-03-06 13:48:40 -08001524 p = kzalloc(sizeof(struct pci_controller_info), GFP_ATOMIC);
David S. Millerbc606f32007-03-01 11:20:37 -08001525 if (!p)
1526 goto memfail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527
David S. Miller16ce82d2007-04-26 21:08:21 -07001528 iommu = kzalloc(sizeof(struct iommu), GFP_ATOMIC);
David S. Millerbc606f32007-03-01 11:20:37 -08001529 if (!iommu)
1530 goto memfail;
1531
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532 p->pbm_A.iommu = iommu;
1533
David S. Miller16ce82d2007-04-26 21:08:21 -07001534 iommu = kzalloc(sizeof(struct iommu), GFP_ATOMIC);
David S. Millerbc606f32007-03-01 11:20:37 -08001535 if (!iommu)
1536 goto memfail;
1537
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538 p->pbm_B.iommu = iommu;
1539
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 /* Like PSYCHO we have a 2GB aligned area for memory space. */
1541 pci_memspace_mask = 0x7fffffffUL;
1542
David S. Millere87dc352006-06-21 18:18:47 -07001543 schizo_pbm_init(p, dp, portid, chip_type);
David S. Millerbc606f32007-03-01 11:20:37 -08001544 return;
1545
1546memfail:
1547 prom_printf("SCHIZO: Fatal memory allocation error.\n");
1548 prom_halt();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549}
1550
David S. Millere87dc352006-06-21 18:18:47 -07001551void schizo_init(struct device_node *dp, char *model_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552{
David S. Millere87dc352006-06-21 18:18:47 -07001553 __schizo_init(dp, model_name, PBM_CHIP_TYPE_SCHIZO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554}
1555
David S. Millere87dc352006-06-21 18:18:47 -07001556void schizo_plus_init(struct device_node *dp, char *model_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557{
David S. Millere87dc352006-06-21 18:18:47 -07001558 __schizo_init(dp, model_name, PBM_CHIP_TYPE_SCHIZO_PLUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559}
1560
David S. Millere87dc352006-06-21 18:18:47 -07001561void tomatillo_init(struct device_node *dp, char *model_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562{
David S. Millere87dc352006-06-21 18:18:47 -07001563 __schizo_init(dp, model_name, PBM_CHIP_TYPE_TOMATILLO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564}