blob: 60605eaf49bb0b846e29849731c8a73572b2607f [file] [log] [blame]
Adrian Bunkb00dc832008-05-19 16:52:27 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * sbus.c: UltraSparc SBUS controller support.
3 *
4 * Copyright (C) 1999 David S. Miller (davem@redhat.com)
5 */
6
7#include <linux/kernel.h>
8#include <linux/types.h>
9#include <linux/mm.h>
10#include <linux/spinlock.h>
11#include <linux/slab.h>
12#include <linux/init.h>
13#include <linux/interrupt.h>
14
15#include <asm/page.h>
16#include <asm/sbus.h>
17#include <asm/io.h>
18#include <asm/upa.h>
19#include <asm/cache.h>
20#include <asm/dma.h>
21#include <asm/irq.h>
David S. Miller25c75812006-06-22 20:21:22 -070022#include <asm/prom.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <asm/starfire.h>
24
25#include "iommu_common.h"
26
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#define MAP_BASE ((u32)0xc0000000)
28
Linus Torvalds1da177e2005-04-16 15:20:36 -070029/* Offsets from iommu_regs */
30#define SYSIO_IOMMUREG_BASE 0x2400UL
31#define IOMMU_CONTROL (0x2400UL - 0x2400UL) /* IOMMU control register */
32#define IOMMU_TSBBASE (0x2408UL - 0x2400UL) /* TSB base address register */
33#define IOMMU_FLUSH (0x2410UL - 0x2400UL) /* IOMMU flush register */
34#define IOMMU_VADIAG (0x4400UL - 0x2400UL) /* SBUS virtual address diagnostic */
35#define IOMMU_TAGCMP (0x4408UL - 0x2400UL) /* TLB tag compare diagnostics */
36#define IOMMU_LRUDIAG (0x4500UL - 0x2400UL) /* IOMMU LRU queue diagnostics */
37#define IOMMU_TAGDIAG (0x4580UL - 0x2400UL) /* TLB tag diagnostics */
38#define IOMMU_DRAMDIAG (0x4600UL - 0x2400UL) /* TLB data RAM diagnostics */
39
40#define IOMMU_DRAM_VALID (1UL << 30UL)
41
Linus Torvalds1da177e2005-04-16 15:20:36 -070042/* Offsets from strbuf_regs */
43#define SYSIO_STRBUFREG_BASE 0x2800UL
44#define STRBUF_CONTROL (0x2800UL - 0x2800UL) /* Control */
45#define STRBUF_PFLUSH (0x2808UL - 0x2800UL) /* Page flush/invalidate */
46#define STRBUF_FSYNC (0x2810UL - 0x2800UL) /* Flush synchronization */
47#define STRBUF_DRAMDIAG (0x5000UL - 0x2800UL) /* data RAM diagnostic */
48#define STRBUF_ERRDIAG (0x5400UL - 0x2800UL) /* error status diagnostics */
49#define STRBUF_PTAGDIAG (0x5800UL - 0x2800UL) /* Page tag diagnostics */
50#define STRBUF_LTAGDIAG (0x5900UL - 0x2800UL) /* Line tag diagnostics */
51
52#define STRBUF_TAG_VALID 0x02UL
53
Linus Torvalds1da177e2005-04-16 15:20:36 -070054/* Enable 64-bit DVMA mode for the given device. */
David S. Miller63237ee2008-08-26 23:33:42 -070055void sbus_set_sbus64(struct device *dev, int bursts)
Linus Torvalds1da177e2005-04-16 15:20:36 -070056{
David S. Miller63237ee2008-08-26 23:33:42 -070057 struct iommu *iommu = dev->archdata.iommu;
58 struct of_device *op = to_of_device(dev);
59 const struct linux_prom_registers *regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 unsigned long cfg_reg;
David S. Miller63237ee2008-08-26 23:33:42 -070061 int slot;
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 u64 val;
63
David S. Miller63237ee2008-08-26 23:33:42 -070064 regs = of_get_property(op->node, "reg", NULL);
65 if (!regs) {
66 printk(KERN_ERR "sbus_set_sbus64: Cannot find regs for %s\n",
67 op->node->full_name);
68 return;
69 }
70 slot = regs->which_io;
71
David S. Miller3e4d2652007-04-25 15:58:22 -070072 cfg_reg = iommu->write_complete_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 switch (slot) {
74 case 0:
75 cfg_reg += 0x20UL;
76 break;
77 case 1:
78 cfg_reg += 0x28UL;
79 break;
80 case 2:
81 cfg_reg += 0x30UL;
82 break;
83 case 3:
84 cfg_reg += 0x38UL;
85 break;
86 case 13:
87 cfg_reg += 0x40UL;
88 break;
89 case 14:
90 cfg_reg += 0x48UL;
91 break;
92 case 15:
93 cfg_reg += 0x50UL;
94 break;
95
96 default:
97 return;
98 };
99
100 val = upa_readq(cfg_reg);
101 if (val & (1UL << 14UL)) {
102 /* Extended transfer mode already enabled. */
103 return;
104 }
105
106 val |= (1UL << 14UL);
107
108 if (bursts & DMA_BURST8)
109 val |= (1UL << 1UL);
110 if (bursts & DMA_BURST16)
111 val |= (1UL << 2UL);
112 if (bursts & DMA_BURST32)
113 val |= (1UL << 3UL);
114 if (bursts & DMA_BURST64)
115 val |= (1UL << 4UL);
116 upa_writeq(val, cfg_reg);
117}
118
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119/* INO number to IMAP register offset for SYSIO external IRQ's.
120 * This should conform to both Sunfire/Wildfire server and Fusion
121 * desktop designs.
122 */
David S. Millerec4d18f2007-06-07 16:58:22 -0700123#define SYSIO_IMAP_SLOT0 0x2c00UL
124#define SYSIO_IMAP_SLOT1 0x2c08UL
125#define SYSIO_IMAP_SLOT2 0x2c10UL
126#define SYSIO_IMAP_SLOT3 0x2c18UL
127#define SYSIO_IMAP_SCSI 0x3000UL
128#define SYSIO_IMAP_ETH 0x3008UL
129#define SYSIO_IMAP_BPP 0x3010UL
130#define SYSIO_IMAP_AUDIO 0x3018UL
131#define SYSIO_IMAP_PFAIL 0x3020UL
132#define SYSIO_IMAP_KMS 0x3028UL
133#define SYSIO_IMAP_FLPY 0x3030UL
134#define SYSIO_IMAP_SHW 0x3038UL
135#define SYSIO_IMAP_KBD 0x3040UL
136#define SYSIO_IMAP_MS 0x3048UL
137#define SYSIO_IMAP_SER 0x3050UL
138#define SYSIO_IMAP_TIM0 0x3060UL
139#define SYSIO_IMAP_TIM1 0x3068UL
140#define SYSIO_IMAP_UE 0x3070UL
141#define SYSIO_IMAP_CE 0x3078UL
142#define SYSIO_IMAP_SBERR 0x3080UL
143#define SYSIO_IMAP_PMGMT 0x3088UL
144#define SYSIO_IMAP_GFX 0x3090UL
145#define SYSIO_IMAP_EUPA 0x3098UL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
147#define bogon ((unsigned long) -1)
148static unsigned long sysio_irq_offsets[] = {
149 /* SBUS Slot 0 --> 3, level 1 --> 7 */
150 SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0,
151 SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0,
152 SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1,
153 SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1,
154 SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2,
155 SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2,
156 SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3,
157 SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3,
158
159 /* Onboard devices (not relevant/used on SunFire). */
160 SYSIO_IMAP_SCSI,
161 SYSIO_IMAP_ETH,
162 SYSIO_IMAP_BPP,
163 bogon,
164 SYSIO_IMAP_AUDIO,
165 SYSIO_IMAP_PFAIL,
166 bogon,
167 bogon,
168 SYSIO_IMAP_KMS,
169 SYSIO_IMAP_FLPY,
170 SYSIO_IMAP_SHW,
171 SYSIO_IMAP_KBD,
172 SYSIO_IMAP_MS,
173 SYSIO_IMAP_SER,
174 bogon,
175 bogon,
176 SYSIO_IMAP_TIM0,
177 SYSIO_IMAP_TIM1,
178 bogon,
179 bogon,
180 SYSIO_IMAP_UE,
181 SYSIO_IMAP_CE,
182 SYSIO_IMAP_SBERR,
183 SYSIO_IMAP_PMGMT,
184};
185
186#undef bogon
187
Tobias Klauser84c1a132005-11-09 12:03:42 -0800188#define NUM_SYSIO_OFFSETS ARRAY_SIZE(sysio_irq_offsets)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
190/* Convert Interrupt Mapping register pointer to associated
191 * Interrupt Clear register pointer, SYSIO specific version.
192 */
193#define SYSIO_ICLR_UNUSED0 0x3400UL
David S. Millerec4d18f2007-06-07 16:58:22 -0700194#define SYSIO_ICLR_SLOT0 0x3408UL
195#define SYSIO_ICLR_SLOT1 0x3448UL
196#define SYSIO_ICLR_SLOT2 0x3488UL
197#define SYSIO_ICLR_SLOT3 0x34c8UL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198static unsigned long sysio_imap_to_iclr(unsigned long imap)
199{
200 unsigned long diff = SYSIO_ICLR_UNUSED0 - SYSIO_IMAP_SLOT0;
201 return imap + diff;
202}
203
David S. Miller046e26a2008-08-27 04:54:04 -0700204static unsigned int sbus_build_irq(struct of_device *op, unsigned int ino)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205{
David S. Miller046e26a2008-08-27 04:54:04 -0700206 struct iommu *iommu = op->dev.archdata.iommu;
David S. Miller3e4d2652007-04-25 15:58:22 -0700207 unsigned long reg_base = iommu->write_complete_reg - 0x2000UL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 unsigned long imap, iclr;
David S. Miller37cdcd92006-06-20 01:21:57 -0700209 int sbus_level = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
211 imap = sysio_irq_offsets[ino];
212 if (imap == ((unsigned long)-1)) {
David S. Miller37cdcd92006-06-20 01:21:57 -0700213 prom_printf("get_irq_translations: Bad SYSIO INO[%x]\n",
214 ino);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 prom_halt();
216 }
217 imap += reg_base;
218
219 /* SYSIO inconsistency. For external SLOTS, we have to select
220 * the right ICLR register based upon the lower SBUS irq level
221 * bits.
222 */
223 if (ino >= 0x20) {
224 iclr = sysio_imap_to_iclr(imap);
225 } else {
226 int sbus_slot = (ino & 0x18)>>3;
227
228 sbus_level = ino & 0x7;
229
230 switch(sbus_slot) {
231 case 0:
232 iclr = reg_base + SYSIO_ICLR_SLOT0;
233 break;
234 case 1:
235 iclr = reg_base + SYSIO_ICLR_SLOT1;
236 break;
237 case 2:
238 iclr = reg_base + SYSIO_ICLR_SLOT2;
239 break;
240 default:
241 case 3:
242 iclr = reg_base + SYSIO_ICLR_SLOT3;
243 break;
244 };
245
246 iclr += ((unsigned long)sbus_level - 1UL) * 8UL;
247 }
David S. Millere18e2a02006-06-20 01:23:32 -0700248 return build_irq(sbus_level, iclr, imap);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249}
250
251/* Error interrupt handling. */
252#define SYSIO_UE_AFSR 0x0030UL
253#define SYSIO_UE_AFAR 0x0038UL
254#define SYSIO_UEAFSR_PPIO 0x8000000000000000UL /* Primary PIO cause */
255#define SYSIO_UEAFSR_PDRD 0x4000000000000000UL /* Primary DVMA read cause */
256#define SYSIO_UEAFSR_PDWR 0x2000000000000000UL /* Primary DVMA write cause */
257#define SYSIO_UEAFSR_SPIO 0x1000000000000000UL /* Secondary PIO is cause */
258#define SYSIO_UEAFSR_SDRD 0x0800000000000000UL /* Secondary DVMA read cause */
259#define SYSIO_UEAFSR_SDWR 0x0400000000000000UL /* Secondary DVMA write cause*/
260#define SYSIO_UEAFSR_RESV1 0x03ff000000000000UL /* Reserved */
261#define SYSIO_UEAFSR_DOFF 0x0000e00000000000UL /* Doubleword Offset */
262#define SYSIO_UEAFSR_SIZE 0x00001c0000000000UL /* Bad transfer size 2^SIZE */
263#define SYSIO_UEAFSR_MID 0x000003e000000000UL /* UPA MID causing the fault */
264#define SYSIO_UEAFSR_RESV2 0x0000001fffffffffUL /* Reserved */
Al Viro6d24c8d2006-10-08 08:23:28 -0400265static irqreturn_t sysio_ue_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266{
David S. Miller046e26a2008-08-27 04:54:04 -0700267 struct of_device *op = dev_id;
268 struct iommu *iommu = op->dev.archdata.iommu;
David S. Miller3e4d2652007-04-25 15:58:22 -0700269 unsigned long reg_base = iommu->write_complete_reg - 0x2000UL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 unsigned long afsr_reg, afar_reg;
271 unsigned long afsr, afar, error_bits;
David S. Miller046e26a2008-08-27 04:54:04 -0700272 int reported, portid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
274 afsr_reg = reg_base + SYSIO_UE_AFSR;
275 afar_reg = reg_base + SYSIO_UE_AFAR;
276
277 /* Latch error status. */
278 afsr = upa_readq(afsr_reg);
279 afar = upa_readq(afar_reg);
280
281 /* Clear primary/secondary error status bits. */
282 error_bits = afsr &
283 (SYSIO_UEAFSR_PPIO | SYSIO_UEAFSR_PDRD | SYSIO_UEAFSR_PDWR |
284 SYSIO_UEAFSR_SPIO | SYSIO_UEAFSR_SDRD | SYSIO_UEAFSR_SDWR);
285 upa_writeq(error_bits, afsr_reg);
286
David S. Miller046e26a2008-08-27 04:54:04 -0700287 portid = of_getintprop_default(op->node, "portid", -1);
288
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 /* Log the error. */
290 printk("SYSIO[%x]: Uncorrectable ECC Error, primary error type[%s]\n",
David S. Miller046e26a2008-08-27 04:54:04 -0700291 portid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 (((error_bits & SYSIO_UEAFSR_PPIO) ?
293 "PIO" :
294 ((error_bits & SYSIO_UEAFSR_PDRD) ?
295 "DVMA Read" :
296 ((error_bits & SYSIO_UEAFSR_PDWR) ?
297 "DVMA Write" : "???")))));
298 printk("SYSIO[%x]: DOFF[%lx] SIZE[%lx] MID[%lx]\n",
David S. Miller046e26a2008-08-27 04:54:04 -0700299 portid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 (afsr & SYSIO_UEAFSR_DOFF) >> 45UL,
301 (afsr & SYSIO_UEAFSR_SIZE) >> 42UL,
302 (afsr & SYSIO_UEAFSR_MID) >> 37UL);
David S. Miller046e26a2008-08-27 04:54:04 -0700303 printk("SYSIO[%x]: AFAR[%016lx]\n", portid, afar);
304 printk("SYSIO[%x]: Secondary UE errors [", portid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 reported = 0;
306 if (afsr & SYSIO_UEAFSR_SPIO) {
307 reported++;
308 printk("(PIO)");
309 }
310 if (afsr & SYSIO_UEAFSR_SDRD) {
311 reported++;
312 printk("(DVMA Read)");
313 }
314 if (afsr & SYSIO_UEAFSR_SDWR) {
315 reported++;
316 printk("(DVMA Write)");
317 }
318 if (!reported)
319 printk("(none)");
320 printk("]\n");
321
322 return IRQ_HANDLED;
323}
324
325#define SYSIO_CE_AFSR 0x0040UL
326#define SYSIO_CE_AFAR 0x0048UL
327#define SYSIO_CEAFSR_PPIO 0x8000000000000000UL /* Primary PIO cause */
328#define SYSIO_CEAFSR_PDRD 0x4000000000000000UL /* Primary DVMA read cause */
329#define SYSIO_CEAFSR_PDWR 0x2000000000000000UL /* Primary DVMA write cause */
330#define SYSIO_CEAFSR_SPIO 0x1000000000000000UL /* Secondary PIO cause */
331#define SYSIO_CEAFSR_SDRD 0x0800000000000000UL /* Secondary DVMA read cause */
332#define SYSIO_CEAFSR_SDWR 0x0400000000000000UL /* Secondary DVMA write cause*/
333#define SYSIO_CEAFSR_RESV1 0x0300000000000000UL /* Reserved */
334#define SYSIO_CEAFSR_ESYND 0x00ff000000000000UL /* Syndrome Bits */
335#define SYSIO_CEAFSR_DOFF 0x0000e00000000000UL /* Double Offset */
336#define SYSIO_CEAFSR_SIZE 0x00001c0000000000UL /* Bad transfer size 2^SIZE */
337#define SYSIO_CEAFSR_MID 0x000003e000000000UL /* UPA MID causing the fault */
338#define SYSIO_CEAFSR_RESV2 0x0000001fffffffffUL /* Reserved */
Al Viro6d24c8d2006-10-08 08:23:28 -0400339static irqreturn_t sysio_ce_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340{
David S. Miller046e26a2008-08-27 04:54:04 -0700341 struct of_device *op = dev_id;
342 struct iommu *iommu = op->dev.archdata.iommu;
David S. Miller3e4d2652007-04-25 15:58:22 -0700343 unsigned long reg_base = iommu->write_complete_reg - 0x2000UL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 unsigned long afsr_reg, afar_reg;
345 unsigned long afsr, afar, error_bits;
David S. Miller046e26a2008-08-27 04:54:04 -0700346 int reported, portid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
348 afsr_reg = reg_base + SYSIO_CE_AFSR;
349 afar_reg = reg_base + SYSIO_CE_AFAR;
350
351 /* Latch error status. */
352 afsr = upa_readq(afsr_reg);
353 afar = upa_readq(afar_reg);
354
355 /* Clear primary/secondary error status bits. */
356 error_bits = afsr &
357 (SYSIO_CEAFSR_PPIO | SYSIO_CEAFSR_PDRD | SYSIO_CEAFSR_PDWR |
358 SYSIO_CEAFSR_SPIO | SYSIO_CEAFSR_SDRD | SYSIO_CEAFSR_SDWR);
359 upa_writeq(error_bits, afsr_reg);
360
David S. Miller046e26a2008-08-27 04:54:04 -0700361 portid = of_getintprop_default(op->node, "portid", -1);
362
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 printk("SYSIO[%x]: Correctable ECC Error, primary error type[%s]\n",
David S. Miller046e26a2008-08-27 04:54:04 -0700364 portid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 (((error_bits & SYSIO_CEAFSR_PPIO) ?
366 "PIO" :
367 ((error_bits & SYSIO_CEAFSR_PDRD) ?
368 "DVMA Read" :
369 ((error_bits & SYSIO_CEAFSR_PDWR) ?
370 "DVMA Write" : "???")))));
371
372 /* XXX Use syndrome and afar to print out module string just like
373 * XXX UDB CE trap handler does... -DaveM
374 */
375 printk("SYSIO[%x]: DOFF[%lx] ECC Syndrome[%lx] Size[%lx] MID[%lx]\n",
David S. Miller046e26a2008-08-27 04:54:04 -0700376 portid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 (afsr & SYSIO_CEAFSR_DOFF) >> 45UL,
378 (afsr & SYSIO_CEAFSR_ESYND) >> 48UL,
379 (afsr & SYSIO_CEAFSR_SIZE) >> 42UL,
380 (afsr & SYSIO_CEAFSR_MID) >> 37UL);
David S. Miller046e26a2008-08-27 04:54:04 -0700381 printk("SYSIO[%x]: AFAR[%016lx]\n", portid, afar);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
David S. Miller046e26a2008-08-27 04:54:04 -0700383 printk("SYSIO[%x]: Secondary CE errors [", portid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 reported = 0;
385 if (afsr & SYSIO_CEAFSR_SPIO) {
386 reported++;
387 printk("(PIO)");
388 }
389 if (afsr & SYSIO_CEAFSR_SDRD) {
390 reported++;
391 printk("(DVMA Read)");
392 }
393 if (afsr & SYSIO_CEAFSR_SDWR) {
394 reported++;
395 printk("(DVMA Write)");
396 }
397 if (!reported)
398 printk("(none)");
399 printk("]\n");
400
401 return IRQ_HANDLED;
402}
403
404#define SYSIO_SBUS_AFSR 0x2010UL
405#define SYSIO_SBUS_AFAR 0x2018UL
406#define SYSIO_SBAFSR_PLE 0x8000000000000000UL /* Primary Late PIO Error */
407#define SYSIO_SBAFSR_PTO 0x4000000000000000UL /* Primary SBUS Timeout */
408#define SYSIO_SBAFSR_PBERR 0x2000000000000000UL /* Primary SBUS Error ACK */
409#define SYSIO_SBAFSR_SLE 0x1000000000000000UL /* Secondary Late PIO Error */
410#define SYSIO_SBAFSR_STO 0x0800000000000000UL /* Secondary SBUS Timeout */
411#define SYSIO_SBAFSR_SBERR 0x0400000000000000UL /* Secondary SBUS Error ACK */
412#define SYSIO_SBAFSR_RESV1 0x03ff000000000000UL /* Reserved */
413#define SYSIO_SBAFSR_RD 0x0000800000000000UL /* Primary was late PIO read */
414#define SYSIO_SBAFSR_RESV2 0x0000600000000000UL /* Reserved */
415#define SYSIO_SBAFSR_SIZE 0x00001c0000000000UL /* Size of transfer */
416#define SYSIO_SBAFSR_MID 0x000003e000000000UL /* MID causing the error */
417#define SYSIO_SBAFSR_RESV3 0x0000001fffffffffUL /* Reserved */
Al Viro6d24c8d2006-10-08 08:23:28 -0400418static irqreturn_t sysio_sbus_error_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419{
David S. Miller046e26a2008-08-27 04:54:04 -0700420 struct of_device *op = dev_id;
421 struct iommu *iommu = op->dev.archdata.iommu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 unsigned long afsr_reg, afar_reg, reg_base;
423 unsigned long afsr, afar, error_bits;
David S. Miller046e26a2008-08-27 04:54:04 -0700424 int reported, portid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
David S. Miller3e4d2652007-04-25 15:58:22 -0700426 reg_base = iommu->write_complete_reg - 0x2000UL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 afsr_reg = reg_base + SYSIO_SBUS_AFSR;
428 afar_reg = reg_base + SYSIO_SBUS_AFAR;
429
430 afsr = upa_readq(afsr_reg);
431 afar = upa_readq(afar_reg);
432
433 /* Clear primary/secondary error status bits. */
434 error_bits = afsr &
435 (SYSIO_SBAFSR_PLE | SYSIO_SBAFSR_PTO | SYSIO_SBAFSR_PBERR |
436 SYSIO_SBAFSR_SLE | SYSIO_SBAFSR_STO | SYSIO_SBAFSR_SBERR);
437 upa_writeq(error_bits, afsr_reg);
438
David S. Miller046e26a2008-08-27 04:54:04 -0700439 portid = of_getintprop_default(op->node, "portid", -1);
440
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 /* Log the error. */
442 printk("SYSIO[%x]: SBUS Error, primary error type[%s] read(%d)\n",
David S. Miller046e26a2008-08-27 04:54:04 -0700443 portid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 (((error_bits & SYSIO_SBAFSR_PLE) ?
445 "Late PIO Error" :
446 ((error_bits & SYSIO_SBAFSR_PTO) ?
447 "Time Out" :
448 ((error_bits & SYSIO_SBAFSR_PBERR) ?
449 "Error Ack" : "???")))),
450 (afsr & SYSIO_SBAFSR_RD) ? 1 : 0);
451 printk("SYSIO[%x]: size[%lx] MID[%lx]\n",
David S. Miller046e26a2008-08-27 04:54:04 -0700452 portid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 (afsr & SYSIO_SBAFSR_SIZE) >> 42UL,
454 (afsr & SYSIO_SBAFSR_MID) >> 37UL);
David S. Miller046e26a2008-08-27 04:54:04 -0700455 printk("SYSIO[%x]: AFAR[%016lx]\n", portid, afar);
456 printk("SYSIO[%x]: Secondary SBUS errors [", portid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 reported = 0;
458 if (afsr & SYSIO_SBAFSR_SLE) {
459 reported++;
460 printk("(Late PIO Error)");
461 }
462 if (afsr & SYSIO_SBAFSR_STO) {
463 reported++;
464 printk("(Time Out)");
465 }
466 if (afsr & SYSIO_SBAFSR_SBERR) {
467 reported++;
468 printk("(Error Ack)");
469 }
470 if (!reported)
471 printk("(none)");
472 printk("]\n");
473
474 /* XXX check iommu/strbuf for further error status XXX */
475
476 return IRQ_HANDLED;
477}
478
479#define ECC_CONTROL 0x0020UL
480#define SYSIO_ECNTRL_ECCEN 0x8000000000000000UL /* Enable ECC Checking */
481#define SYSIO_ECNTRL_UEEN 0x4000000000000000UL /* Enable UE Interrupts */
482#define SYSIO_ECNTRL_CEEN 0x2000000000000000UL /* Enable CE Interrupts */
483
484#define SYSIO_UE_INO 0x34
485#define SYSIO_CE_INO 0x35
486#define SYSIO_SBUSERR_INO 0x36
487
David S. Miller046e26a2008-08-27 04:54:04 -0700488static void __init sysio_register_error_handlers(struct of_device *op)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489{
David S. Miller046e26a2008-08-27 04:54:04 -0700490 struct iommu *iommu = op->dev.archdata.iommu;
David S. Miller3e4d2652007-04-25 15:58:22 -0700491 unsigned long reg_base = iommu->write_complete_reg - 0x2000UL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 unsigned int irq;
493 u64 control;
David S. Miller046e26a2008-08-27 04:54:04 -0700494 int portid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
David S. Miller046e26a2008-08-27 04:54:04 -0700496 portid = of_getintprop_default(op->node, "portid", -1);
497
498 irq = sbus_build_irq(op, SYSIO_UE_INO);
David S. Miller96a496f2007-05-07 23:08:39 -0700499 if (request_irq(irq, sysio_ue_handler, 0,
David S. Miller046e26a2008-08-27 04:54:04 -0700500 "SYSIO_UE", op) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 prom_printf("SYSIO[%x]: Cannot register UE interrupt.\n",
David S. Miller046e26a2008-08-27 04:54:04 -0700502 portid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 prom_halt();
504 }
505
David S. Miller046e26a2008-08-27 04:54:04 -0700506 irq = sbus_build_irq(op, SYSIO_CE_INO);
David S. Miller96a496f2007-05-07 23:08:39 -0700507 if (request_irq(irq, sysio_ce_handler, 0,
David S. Miller046e26a2008-08-27 04:54:04 -0700508 "SYSIO_CE", op) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 prom_printf("SYSIO[%x]: Cannot register CE interrupt.\n",
David S. Miller046e26a2008-08-27 04:54:04 -0700510 portid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 prom_halt();
512 }
513
David S. Miller046e26a2008-08-27 04:54:04 -0700514 irq = sbus_build_irq(op, SYSIO_SBUSERR_INO);
David S. Miller96a496f2007-05-07 23:08:39 -0700515 if (request_irq(irq, sysio_sbus_error_handler, 0,
David S. Miller046e26a2008-08-27 04:54:04 -0700516 "SYSIO_SBERR", op) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 prom_printf("SYSIO[%x]: Cannot register SBUS Error interrupt.\n",
David S. Miller046e26a2008-08-27 04:54:04 -0700518 portid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 prom_halt();
520 }
521
522 /* Now turn the error interrupts on and also enable ECC checking. */
523 upa_writeq((SYSIO_ECNTRL_ECCEN |
524 SYSIO_ECNTRL_UEEN |
525 SYSIO_ECNTRL_CEEN),
526 reg_base + ECC_CONTROL);
527
David S. Miller3e4d2652007-04-25 15:58:22 -0700528 control = upa_readq(iommu->write_complete_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 control |= 0x100UL; /* SBUS Error Interrupt Enable */
David S. Miller3e4d2652007-04-25 15:58:22 -0700530 upa_writeq(control, iommu->write_complete_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531}
532
533/* Boot time initialization. */
David S. Miller046e26a2008-08-27 04:54:04 -0700534static void __init sbus_iommu_init(struct of_device *op)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535{
Stephen Rothwell6a23acf2007-04-23 15:53:27 -0700536 const struct linux_prom64_registers *pr;
David S. Miller046e26a2008-08-27 04:54:04 -0700537 struct device_node *dp = op->node;
David S. Miller3e4d2652007-04-25 15:58:22 -0700538 struct iommu *iommu;
539 struct strbuf *strbuf;
540 unsigned long regs, reg_base;
David S. Miller046e26a2008-08-27 04:54:04 -0700541 int i, portid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 u64 control;
David S. Miller25c75812006-06-22 20:21:22 -0700543
544 pr = of_get_property(dp, "reg", NULL);
545 if (!pr) {
David S. Millerad7ad572007-07-27 22:39:14 -0700546 prom_printf("sbus_iommu_init: Cannot map SYSIO "
547 "control registers.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 prom_halt();
549 }
David S. Miller25c75812006-06-22 20:21:22 -0700550 regs = pr->phys_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
David S. Millerad7ad572007-07-27 22:39:14 -0700552 iommu = kzalloc(sizeof(*iommu), GFP_ATOMIC);
553 if (!iommu)
554 goto fatal_memory_error;
555 strbuf = kzalloc(sizeof(*strbuf), GFP_ATOMIC);
556 if (!strbuf)
557 goto fatal_memory_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558
David S. Miller046e26a2008-08-27 04:54:04 -0700559 op->dev.archdata.iommu = iommu;
560 op->dev.archdata.stc = strbuf;
561 op->dev.archdata.numa_node = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
David S. Miller3e4d2652007-04-25 15:58:22 -0700563 reg_base = regs + SYSIO_IOMMUREG_BASE;
564 iommu->iommu_control = reg_base + IOMMU_CONTROL;
565 iommu->iommu_tsbbase = reg_base + IOMMU_TSBBASE;
566 iommu->iommu_flush = reg_base + IOMMU_FLUSH;
David S. Millerad7ad572007-07-27 22:39:14 -0700567 iommu->iommu_tags = iommu->iommu_control +
568 (IOMMU_TAGDIAG - IOMMU_CONTROL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569
David S. Miller3e4d2652007-04-25 15:58:22 -0700570 reg_base = regs + SYSIO_STRBUFREG_BASE;
571 strbuf->strbuf_control = reg_base + STRBUF_CONTROL;
572 strbuf->strbuf_pflush = reg_base + STRBUF_PFLUSH;
573 strbuf->strbuf_fsync = reg_base + STRBUF_FSYNC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574
David S. Miller3e4d2652007-04-25 15:58:22 -0700575 strbuf->strbuf_enabled = 1;
576
577 strbuf->strbuf_flushflag = (volatile unsigned long *)
578 ((((unsigned long)&strbuf->__flushflag_buf[0])
579 + 63UL)
580 & ~63UL);
581 strbuf->strbuf_flushflag_pa = (unsigned long)
582 __pa(strbuf->strbuf_flushflag);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583
584 /* The SYSIO SBUS control register is used for dummy reads
585 * in order to ensure write completion.
586 */
David S. Miller3e4d2652007-04-25 15:58:22 -0700587 iommu->write_complete_reg = regs + 0x2000UL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588
David S. Miller046e26a2008-08-27 04:54:04 -0700589 portid = of_getintprop_default(op->node, "portid", -1);
590 printk(KERN_INFO "SYSIO: UPA portID %x, at %016lx\n",
591 portid, regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592
593 /* Setup for TSB_SIZE=7, TBW_SIZE=0, MMU_DE=1, MMU_EN=1 */
David S. Millerc1b1a5f2008-03-19 04:52:48 -0700594 if (iommu_table_init(iommu, IO_TSB_SIZE, MAP_BASE, 0xffffffff, -1))
David S. Millerad7ad572007-07-27 22:39:14 -0700595 goto fatal_memory_error;
David S. Miller2f3a2ef2007-04-11 21:38:45 -0700596
David S. Miller3e4d2652007-04-25 15:58:22 -0700597 control = upa_readq(iommu->iommu_control);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 control = ((7UL << 16UL) |
599 (0UL << 2UL) |
600 (1UL << 1UL) |
601 (1UL << 0UL));
David S. Miller3e4d2652007-04-25 15:58:22 -0700602 upa_writeq(control, iommu->iommu_control);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603
604 /* Clean out any cruft in the IOMMU using
605 * diagnostic accesses.
606 */
607 for (i = 0; i < 16; i++) {
David S. Miller3e4d2652007-04-25 15:58:22 -0700608 unsigned long dram, tag;
609
610 dram = iommu->iommu_control + (IOMMU_DRAMDIAG - IOMMU_CONTROL);
611 tag = iommu->iommu_control + (IOMMU_TAGDIAG - IOMMU_CONTROL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612
613 dram += (unsigned long)i * 8UL;
614 tag += (unsigned long)i * 8UL;
615 upa_writeq(0, dram);
616 upa_writeq(0, tag);
617 }
David S. Miller3e4d2652007-04-25 15:58:22 -0700618 upa_readq(iommu->write_complete_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619
620 /* Give the TSB to SYSIO. */
David S. Miller3e4d2652007-04-25 15:58:22 -0700621 upa_writeq(__pa(iommu->page_table), iommu->iommu_tsbbase);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622
623 /* Setup streaming buffer, DE=1 SB_EN=1 */
624 control = (1UL << 1UL) | (1UL << 0UL);
David S. Miller3e4d2652007-04-25 15:58:22 -0700625 upa_writeq(control, strbuf->strbuf_control);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626
627 /* Clear out the tags using diagnostics. */
628 for (i = 0; i < 16; i++) {
629 unsigned long ptag, ltag;
630
David S. Miller3e4d2652007-04-25 15:58:22 -0700631 ptag = strbuf->strbuf_control +
632 (STRBUF_PTAGDIAG - STRBUF_CONTROL);
633 ltag = strbuf->strbuf_control +
634 (STRBUF_LTAGDIAG - STRBUF_CONTROL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 ptag += (unsigned long)i * 8UL;
636 ltag += (unsigned long)i * 8UL;
637
638 upa_writeq(0UL, ptag);
639 upa_writeq(0UL, ltag);
640 }
641
642 /* Enable DVMA arbitration for all devices/slots. */
David S. Miller3e4d2652007-04-25 15:58:22 -0700643 control = upa_readq(iommu->write_complete_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 control |= 0x3fUL;
David S. Miller3e4d2652007-04-25 15:58:22 -0700645 upa_writeq(control, iommu->write_complete_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646
647 /* Now some Xfire specific grot... */
648 if (this_is_starfire)
David S. Miller046e26a2008-08-27 04:54:04 -0700649 starfire_hookup(portid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650
David S. Miller046e26a2008-08-27 04:54:04 -0700651 sysio_register_error_handlers(op);
David S. Millerad7ad572007-07-27 22:39:14 -0700652 return;
653
654fatal_memory_error:
655 prom_printf("sbus_iommu_init: Fatal memory allocation error.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656}
David S. Miller8fae0972006-06-20 15:23:28 -0700657
David S. Miller046e26a2008-08-27 04:54:04 -0700658static int __init sbus_init(void)
David S. Miller576c3522006-06-23 15:55:45 -0700659{
660 extern void firetruck_init(void);
David S. Miller046e26a2008-08-27 04:54:04 -0700661 struct device_node *dp;
662
663 for_each_node_by_name(dp, "sbus") {
664 struct of_device *op = of_find_device_by_node(dp);
665
666 sbus_iommu_init(op);
667 of_propagate_archdata(op);
668 }
David S. Miller576c3522006-06-23 15:55:45 -0700669
670 firetruck_init();
David S. Miller046e26a2008-08-27 04:54:04 -0700671
672 return 0;
David S. Miller576c3522006-06-23 15:55:45 -0700673}
David S. Miller046e26a2008-08-27 04:54:04 -0700674
675subsys_initcall(sbus_init);