blob: be5bdf93c7676cfedffd91d645bffa3fe9cff419 [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>
Paul Gortmaker7b64db62011-07-18 15:57:46 -040012#include <linux/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/init.h>
14#include <linux/interrupt.h>
David S. Miller9dc69232008-08-27 19:54:01 -070015#include <linux/of.h>
16#include <linux/of_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
18#include <asm/page.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <asm/io.h>
20#include <asm/upa.h>
21#include <asm/cache.h>
22#include <asm/dma.h>
23#include <asm/irq.h>
David S. Miller25c75812006-06-22 20:21:22 -070024#include <asm/prom.h>
David S. Miller9dc69232008-08-27 19:54:01 -070025#include <asm/oplib.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <asm/starfire.h>
27
28#include "iommu_common.h"
29
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#define MAP_BASE ((u32)0xc0000000)
31
Linus Torvalds1da177e2005-04-16 15:20:36 -070032/* Offsets from iommu_regs */
33#define SYSIO_IOMMUREG_BASE 0x2400UL
34#define IOMMU_CONTROL (0x2400UL - 0x2400UL) /* IOMMU control register */
35#define IOMMU_TSBBASE (0x2408UL - 0x2400UL) /* TSB base address register */
36#define IOMMU_FLUSH (0x2410UL - 0x2400UL) /* IOMMU flush register */
37#define IOMMU_VADIAG (0x4400UL - 0x2400UL) /* SBUS virtual address diagnostic */
38#define IOMMU_TAGCMP (0x4408UL - 0x2400UL) /* TLB tag compare diagnostics */
39#define IOMMU_LRUDIAG (0x4500UL - 0x2400UL) /* IOMMU LRU queue diagnostics */
40#define IOMMU_TAGDIAG (0x4580UL - 0x2400UL) /* TLB tag diagnostics */
41#define IOMMU_DRAMDIAG (0x4600UL - 0x2400UL) /* TLB data RAM diagnostics */
42
43#define IOMMU_DRAM_VALID (1UL << 30UL)
44
Linus Torvalds1da177e2005-04-16 15:20:36 -070045/* Offsets from strbuf_regs */
46#define SYSIO_STRBUFREG_BASE 0x2800UL
47#define STRBUF_CONTROL (0x2800UL - 0x2800UL) /* Control */
48#define STRBUF_PFLUSH (0x2808UL - 0x2800UL) /* Page flush/invalidate */
49#define STRBUF_FSYNC (0x2810UL - 0x2800UL) /* Flush synchronization */
50#define STRBUF_DRAMDIAG (0x5000UL - 0x2800UL) /* data RAM diagnostic */
51#define STRBUF_ERRDIAG (0x5400UL - 0x2800UL) /* error status diagnostics */
52#define STRBUF_PTAGDIAG (0x5800UL - 0x2800UL) /* Page tag diagnostics */
53#define STRBUF_LTAGDIAG (0x5900UL - 0x2800UL) /* Line tag diagnostics */
54
55#define STRBUF_TAG_VALID 0x02UL
56
Linus Torvalds1da177e2005-04-16 15:20:36 -070057/* Enable 64-bit DVMA mode for the given device. */
David S. Miller63237ee2008-08-26 23:33:42 -070058void sbus_set_sbus64(struct device *dev, int bursts)
Linus Torvalds1da177e2005-04-16 15:20:36 -070059{
David S. Miller63237ee2008-08-26 23:33:42 -070060 struct iommu *iommu = dev->archdata.iommu;
Grant Likelycd4cd732010-07-22 16:04:30 -060061 struct platform_device *op = to_platform_device(dev);
David S. Miller63237ee2008-08-26 23:33:42 -070062 const struct linux_prom_registers *regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 unsigned long cfg_reg;
David S. Miller63237ee2008-08-26 23:33:42 -070064 int slot;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 u64 val;
66
Grant Likely61c7a082010-04-13 16:12:29 -070067 regs = of_get_property(op->dev.of_node, "reg", NULL);
David S. Miller63237ee2008-08-26 23:33:42 -070068 if (!regs) {
69 printk(KERN_ERR "sbus_set_sbus64: Cannot find regs for %s\n",
Grant Likely61c7a082010-04-13 16:12:29 -070070 op->dev.of_node->full_name);
David S. Miller63237ee2008-08-26 23:33:42 -070071 return;
72 }
73 slot = regs->which_io;
74
David S. Miller3e4d2652007-04-25 15:58:22 -070075 cfg_reg = iommu->write_complete_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 switch (slot) {
77 case 0:
78 cfg_reg += 0x20UL;
79 break;
80 case 1:
81 cfg_reg += 0x28UL;
82 break;
83 case 2:
84 cfg_reg += 0x30UL;
85 break;
86 case 3:
87 cfg_reg += 0x38UL;
88 break;
89 case 13:
90 cfg_reg += 0x40UL;
91 break;
92 case 14:
93 cfg_reg += 0x48UL;
94 break;
95 case 15:
96 cfg_reg += 0x50UL;
97 break;
98
99 default:
100 return;
Joe Perches6cb79b32011-06-03 14:45:23 +0000101 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
103 val = upa_readq(cfg_reg);
104 if (val & (1UL << 14UL)) {
105 /* Extended transfer mode already enabled. */
106 return;
107 }
108
109 val |= (1UL << 14UL);
110
111 if (bursts & DMA_BURST8)
112 val |= (1UL << 1UL);
113 if (bursts & DMA_BURST16)
114 val |= (1UL << 2UL);
115 if (bursts & DMA_BURST32)
116 val |= (1UL << 3UL);
117 if (bursts & DMA_BURST64)
118 val |= (1UL << 4UL);
119 upa_writeq(val, cfg_reg);
120}
Sam Ravnborg917c3662009-01-08 16:58:20 -0800121EXPORT_SYMBOL(sbus_set_sbus64);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123/* INO number to IMAP register offset for SYSIO external IRQ's.
124 * This should conform to both Sunfire/Wildfire server and Fusion
125 * desktop designs.
126 */
David S. Millerec4d18f2007-06-07 16:58:22 -0700127#define SYSIO_IMAP_SLOT0 0x2c00UL
128#define SYSIO_IMAP_SLOT1 0x2c08UL
129#define SYSIO_IMAP_SLOT2 0x2c10UL
130#define SYSIO_IMAP_SLOT3 0x2c18UL
131#define SYSIO_IMAP_SCSI 0x3000UL
132#define SYSIO_IMAP_ETH 0x3008UL
133#define SYSIO_IMAP_BPP 0x3010UL
134#define SYSIO_IMAP_AUDIO 0x3018UL
135#define SYSIO_IMAP_PFAIL 0x3020UL
136#define SYSIO_IMAP_KMS 0x3028UL
137#define SYSIO_IMAP_FLPY 0x3030UL
138#define SYSIO_IMAP_SHW 0x3038UL
139#define SYSIO_IMAP_KBD 0x3040UL
140#define SYSIO_IMAP_MS 0x3048UL
141#define SYSIO_IMAP_SER 0x3050UL
142#define SYSIO_IMAP_TIM0 0x3060UL
143#define SYSIO_IMAP_TIM1 0x3068UL
144#define SYSIO_IMAP_UE 0x3070UL
145#define SYSIO_IMAP_CE 0x3078UL
146#define SYSIO_IMAP_SBERR 0x3080UL
147#define SYSIO_IMAP_PMGMT 0x3088UL
148#define SYSIO_IMAP_GFX 0x3090UL
149#define SYSIO_IMAP_EUPA 0x3098UL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
151#define bogon ((unsigned long) -1)
152static unsigned long sysio_irq_offsets[] = {
153 /* SBUS Slot 0 --> 3, level 1 --> 7 */
154 SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0,
155 SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0,
156 SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1,
157 SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1,
158 SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2,
159 SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2,
160 SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3,
161 SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3,
162
163 /* Onboard devices (not relevant/used on SunFire). */
164 SYSIO_IMAP_SCSI,
165 SYSIO_IMAP_ETH,
166 SYSIO_IMAP_BPP,
167 bogon,
168 SYSIO_IMAP_AUDIO,
169 SYSIO_IMAP_PFAIL,
170 bogon,
171 bogon,
172 SYSIO_IMAP_KMS,
173 SYSIO_IMAP_FLPY,
174 SYSIO_IMAP_SHW,
175 SYSIO_IMAP_KBD,
176 SYSIO_IMAP_MS,
177 SYSIO_IMAP_SER,
178 bogon,
179 bogon,
180 SYSIO_IMAP_TIM0,
181 SYSIO_IMAP_TIM1,
182 bogon,
183 bogon,
184 SYSIO_IMAP_UE,
185 SYSIO_IMAP_CE,
186 SYSIO_IMAP_SBERR,
187 SYSIO_IMAP_PMGMT,
188};
189
190#undef bogon
191
Tobias Klauser84c1a132005-11-09 12:03:42 -0800192#define NUM_SYSIO_OFFSETS ARRAY_SIZE(sysio_irq_offsets)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
194/* Convert Interrupt Mapping register pointer to associated
195 * Interrupt Clear register pointer, SYSIO specific version.
196 */
197#define SYSIO_ICLR_UNUSED0 0x3400UL
David S. Millerec4d18f2007-06-07 16:58:22 -0700198#define SYSIO_ICLR_SLOT0 0x3408UL
199#define SYSIO_ICLR_SLOT1 0x3448UL
200#define SYSIO_ICLR_SLOT2 0x3488UL
201#define SYSIO_ICLR_SLOT3 0x34c8UL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202static unsigned long sysio_imap_to_iclr(unsigned long imap)
203{
204 unsigned long diff = SYSIO_ICLR_UNUSED0 - SYSIO_IMAP_SLOT0;
205 return imap + diff;
206}
207
Grant Likelycd4cd732010-07-22 16:04:30 -0600208static unsigned int sbus_build_irq(struct platform_device *op, unsigned int ino)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209{
David S. Miller046e26a2008-08-27 04:54:04 -0700210 struct iommu *iommu = op->dev.archdata.iommu;
David S. Miller3e4d2652007-04-25 15:58:22 -0700211 unsigned long reg_base = iommu->write_complete_reg - 0x2000UL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 unsigned long imap, iclr;
David S. Miller37cdcd92006-06-20 01:21:57 -0700213 int sbus_level = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
215 imap = sysio_irq_offsets[ino];
216 if (imap == ((unsigned long)-1)) {
David S. Miller37cdcd92006-06-20 01:21:57 -0700217 prom_printf("get_irq_translations: Bad SYSIO INO[%x]\n",
218 ino);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 prom_halt();
220 }
221 imap += reg_base;
222
223 /* SYSIO inconsistency. For external SLOTS, we have to select
224 * the right ICLR register based upon the lower SBUS irq level
225 * bits.
226 */
227 if (ino >= 0x20) {
228 iclr = sysio_imap_to_iclr(imap);
229 } else {
230 int sbus_slot = (ino & 0x18)>>3;
231
232 sbus_level = ino & 0x7;
233
234 switch(sbus_slot) {
235 case 0:
236 iclr = reg_base + SYSIO_ICLR_SLOT0;
237 break;
238 case 1:
239 iclr = reg_base + SYSIO_ICLR_SLOT1;
240 break;
241 case 2:
242 iclr = reg_base + SYSIO_ICLR_SLOT2;
243 break;
244 default:
245 case 3:
246 iclr = reg_base + SYSIO_ICLR_SLOT3;
247 break;
Joe Perches6cb79b32011-06-03 14:45:23 +0000248 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
250 iclr += ((unsigned long)sbus_level - 1UL) * 8UL;
251 }
David S. Millere18e2a02006-06-20 01:23:32 -0700252 return build_irq(sbus_level, iclr, imap);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253}
254
255/* Error interrupt handling. */
256#define SYSIO_UE_AFSR 0x0030UL
257#define SYSIO_UE_AFAR 0x0038UL
258#define SYSIO_UEAFSR_PPIO 0x8000000000000000UL /* Primary PIO cause */
259#define SYSIO_UEAFSR_PDRD 0x4000000000000000UL /* Primary DVMA read cause */
260#define SYSIO_UEAFSR_PDWR 0x2000000000000000UL /* Primary DVMA write cause */
261#define SYSIO_UEAFSR_SPIO 0x1000000000000000UL /* Secondary PIO is cause */
262#define SYSIO_UEAFSR_SDRD 0x0800000000000000UL /* Secondary DVMA read cause */
263#define SYSIO_UEAFSR_SDWR 0x0400000000000000UL /* Secondary DVMA write cause*/
264#define SYSIO_UEAFSR_RESV1 0x03ff000000000000UL /* Reserved */
265#define SYSIO_UEAFSR_DOFF 0x0000e00000000000UL /* Doubleword Offset */
266#define SYSIO_UEAFSR_SIZE 0x00001c0000000000UL /* Bad transfer size 2^SIZE */
267#define SYSIO_UEAFSR_MID 0x000003e000000000UL /* UPA MID causing the fault */
268#define SYSIO_UEAFSR_RESV2 0x0000001fffffffffUL /* Reserved */
Al Viro6d24c8d2006-10-08 08:23:28 -0400269static irqreturn_t sysio_ue_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270{
Grant Likelycd4cd732010-07-22 16:04:30 -0600271 struct platform_device *op = dev_id;
David S. Miller046e26a2008-08-27 04:54:04 -0700272 struct iommu *iommu = op->dev.archdata.iommu;
David S. Miller3e4d2652007-04-25 15:58:22 -0700273 unsigned long reg_base = iommu->write_complete_reg - 0x2000UL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 unsigned long afsr_reg, afar_reg;
275 unsigned long afsr, afar, error_bits;
David S. Miller046e26a2008-08-27 04:54:04 -0700276 int reported, portid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
278 afsr_reg = reg_base + SYSIO_UE_AFSR;
279 afar_reg = reg_base + SYSIO_UE_AFAR;
280
281 /* Latch error status. */
282 afsr = upa_readq(afsr_reg);
283 afar = upa_readq(afar_reg);
284
285 /* Clear primary/secondary error status bits. */
286 error_bits = afsr &
287 (SYSIO_UEAFSR_PPIO | SYSIO_UEAFSR_PDRD | SYSIO_UEAFSR_PDWR |
288 SYSIO_UEAFSR_SPIO | SYSIO_UEAFSR_SDRD | SYSIO_UEAFSR_SDWR);
289 upa_writeq(error_bits, afsr_reg);
290
Grant Likely61c7a082010-04-13 16:12:29 -0700291 portid = of_getintprop_default(op->dev.of_node, "portid", -1);
David S. Miller046e26a2008-08-27 04:54:04 -0700292
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 /* Log the error. */
294 printk("SYSIO[%x]: Uncorrectable ECC Error, primary error type[%s]\n",
David S. Miller046e26a2008-08-27 04:54:04 -0700295 portid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 (((error_bits & SYSIO_UEAFSR_PPIO) ?
297 "PIO" :
298 ((error_bits & SYSIO_UEAFSR_PDRD) ?
299 "DVMA Read" :
300 ((error_bits & SYSIO_UEAFSR_PDWR) ?
301 "DVMA Write" : "???")))));
302 printk("SYSIO[%x]: DOFF[%lx] SIZE[%lx] MID[%lx]\n",
David S. Miller046e26a2008-08-27 04:54:04 -0700303 portid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 (afsr & SYSIO_UEAFSR_DOFF) >> 45UL,
305 (afsr & SYSIO_UEAFSR_SIZE) >> 42UL,
306 (afsr & SYSIO_UEAFSR_MID) >> 37UL);
David S. Miller046e26a2008-08-27 04:54:04 -0700307 printk("SYSIO[%x]: AFAR[%016lx]\n", portid, afar);
308 printk("SYSIO[%x]: Secondary UE errors [", portid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 reported = 0;
310 if (afsr & SYSIO_UEAFSR_SPIO) {
311 reported++;
312 printk("(PIO)");
313 }
314 if (afsr & SYSIO_UEAFSR_SDRD) {
315 reported++;
316 printk("(DVMA Read)");
317 }
318 if (afsr & SYSIO_UEAFSR_SDWR) {
319 reported++;
320 printk("(DVMA Write)");
321 }
322 if (!reported)
323 printk("(none)");
324 printk("]\n");
325
326 return IRQ_HANDLED;
327}
328
329#define SYSIO_CE_AFSR 0x0040UL
330#define SYSIO_CE_AFAR 0x0048UL
331#define SYSIO_CEAFSR_PPIO 0x8000000000000000UL /* Primary PIO cause */
332#define SYSIO_CEAFSR_PDRD 0x4000000000000000UL /* Primary DVMA read cause */
333#define SYSIO_CEAFSR_PDWR 0x2000000000000000UL /* Primary DVMA write cause */
334#define SYSIO_CEAFSR_SPIO 0x1000000000000000UL /* Secondary PIO cause */
335#define SYSIO_CEAFSR_SDRD 0x0800000000000000UL /* Secondary DVMA read cause */
336#define SYSIO_CEAFSR_SDWR 0x0400000000000000UL /* Secondary DVMA write cause*/
337#define SYSIO_CEAFSR_RESV1 0x0300000000000000UL /* Reserved */
338#define SYSIO_CEAFSR_ESYND 0x00ff000000000000UL /* Syndrome Bits */
339#define SYSIO_CEAFSR_DOFF 0x0000e00000000000UL /* Double Offset */
340#define SYSIO_CEAFSR_SIZE 0x00001c0000000000UL /* Bad transfer size 2^SIZE */
341#define SYSIO_CEAFSR_MID 0x000003e000000000UL /* UPA MID causing the fault */
342#define SYSIO_CEAFSR_RESV2 0x0000001fffffffffUL /* Reserved */
Al Viro6d24c8d2006-10-08 08:23:28 -0400343static irqreturn_t sysio_ce_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344{
Grant Likelycd4cd732010-07-22 16:04:30 -0600345 struct platform_device *op = dev_id;
David S. Miller046e26a2008-08-27 04:54:04 -0700346 struct iommu *iommu = op->dev.archdata.iommu;
David S. Miller3e4d2652007-04-25 15:58:22 -0700347 unsigned long reg_base = iommu->write_complete_reg - 0x2000UL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 unsigned long afsr_reg, afar_reg;
349 unsigned long afsr, afar, error_bits;
David S. Miller046e26a2008-08-27 04:54:04 -0700350 int reported, portid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
352 afsr_reg = reg_base + SYSIO_CE_AFSR;
353 afar_reg = reg_base + SYSIO_CE_AFAR;
354
355 /* Latch error status. */
356 afsr = upa_readq(afsr_reg);
357 afar = upa_readq(afar_reg);
358
359 /* Clear primary/secondary error status bits. */
360 error_bits = afsr &
361 (SYSIO_CEAFSR_PPIO | SYSIO_CEAFSR_PDRD | SYSIO_CEAFSR_PDWR |
362 SYSIO_CEAFSR_SPIO | SYSIO_CEAFSR_SDRD | SYSIO_CEAFSR_SDWR);
363 upa_writeq(error_bits, afsr_reg);
364
Grant Likely61c7a082010-04-13 16:12:29 -0700365 portid = of_getintprop_default(op->dev.of_node, "portid", -1);
David S. Miller046e26a2008-08-27 04:54:04 -0700366
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 printk("SYSIO[%x]: Correctable ECC Error, primary error type[%s]\n",
David S. Miller046e26a2008-08-27 04:54:04 -0700368 portid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 (((error_bits & SYSIO_CEAFSR_PPIO) ?
370 "PIO" :
371 ((error_bits & SYSIO_CEAFSR_PDRD) ?
372 "DVMA Read" :
373 ((error_bits & SYSIO_CEAFSR_PDWR) ?
374 "DVMA Write" : "???")))));
375
376 /* XXX Use syndrome and afar to print out module string just like
377 * XXX UDB CE trap handler does... -DaveM
378 */
379 printk("SYSIO[%x]: DOFF[%lx] ECC Syndrome[%lx] Size[%lx] MID[%lx]\n",
David S. Miller046e26a2008-08-27 04:54:04 -0700380 portid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 (afsr & SYSIO_CEAFSR_DOFF) >> 45UL,
382 (afsr & SYSIO_CEAFSR_ESYND) >> 48UL,
383 (afsr & SYSIO_CEAFSR_SIZE) >> 42UL,
384 (afsr & SYSIO_CEAFSR_MID) >> 37UL);
David S. Miller046e26a2008-08-27 04:54:04 -0700385 printk("SYSIO[%x]: AFAR[%016lx]\n", portid, afar);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386
David S. Miller046e26a2008-08-27 04:54:04 -0700387 printk("SYSIO[%x]: Secondary CE errors [", portid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 reported = 0;
389 if (afsr & SYSIO_CEAFSR_SPIO) {
390 reported++;
391 printk("(PIO)");
392 }
393 if (afsr & SYSIO_CEAFSR_SDRD) {
394 reported++;
395 printk("(DVMA Read)");
396 }
397 if (afsr & SYSIO_CEAFSR_SDWR) {
398 reported++;
399 printk("(DVMA Write)");
400 }
401 if (!reported)
402 printk("(none)");
403 printk("]\n");
404
405 return IRQ_HANDLED;
406}
407
408#define SYSIO_SBUS_AFSR 0x2010UL
409#define SYSIO_SBUS_AFAR 0x2018UL
410#define SYSIO_SBAFSR_PLE 0x8000000000000000UL /* Primary Late PIO Error */
411#define SYSIO_SBAFSR_PTO 0x4000000000000000UL /* Primary SBUS Timeout */
412#define SYSIO_SBAFSR_PBERR 0x2000000000000000UL /* Primary SBUS Error ACK */
413#define SYSIO_SBAFSR_SLE 0x1000000000000000UL /* Secondary Late PIO Error */
414#define SYSIO_SBAFSR_STO 0x0800000000000000UL /* Secondary SBUS Timeout */
415#define SYSIO_SBAFSR_SBERR 0x0400000000000000UL /* Secondary SBUS Error ACK */
416#define SYSIO_SBAFSR_RESV1 0x03ff000000000000UL /* Reserved */
417#define SYSIO_SBAFSR_RD 0x0000800000000000UL /* Primary was late PIO read */
418#define SYSIO_SBAFSR_RESV2 0x0000600000000000UL /* Reserved */
419#define SYSIO_SBAFSR_SIZE 0x00001c0000000000UL /* Size of transfer */
420#define SYSIO_SBAFSR_MID 0x000003e000000000UL /* MID causing the error */
421#define SYSIO_SBAFSR_RESV3 0x0000001fffffffffUL /* Reserved */
Al Viro6d24c8d2006-10-08 08:23:28 -0400422static irqreturn_t sysio_sbus_error_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423{
Grant Likelycd4cd732010-07-22 16:04:30 -0600424 struct platform_device *op = dev_id;
David S. Miller046e26a2008-08-27 04:54:04 -0700425 struct iommu *iommu = op->dev.archdata.iommu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 unsigned long afsr_reg, afar_reg, reg_base;
427 unsigned long afsr, afar, error_bits;
David S. Miller046e26a2008-08-27 04:54:04 -0700428 int reported, portid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
David S. Miller3e4d2652007-04-25 15:58:22 -0700430 reg_base = iommu->write_complete_reg - 0x2000UL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 afsr_reg = reg_base + SYSIO_SBUS_AFSR;
432 afar_reg = reg_base + SYSIO_SBUS_AFAR;
433
434 afsr = upa_readq(afsr_reg);
435 afar = upa_readq(afar_reg);
436
437 /* Clear primary/secondary error status bits. */
438 error_bits = afsr &
439 (SYSIO_SBAFSR_PLE | SYSIO_SBAFSR_PTO | SYSIO_SBAFSR_PBERR |
440 SYSIO_SBAFSR_SLE | SYSIO_SBAFSR_STO | SYSIO_SBAFSR_SBERR);
441 upa_writeq(error_bits, afsr_reg);
442
Grant Likely61c7a082010-04-13 16:12:29 -0700443 portid = of_getintprop_default(op->dev.of_node, "portid", -1);
David S. Miller046e26a2008-08-27 04:54:04 -0700444
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 /* Log the error. */
446 printk("SYSIO[%x]: SBUS Error, primary error type[%s] read(%d)\n",
David S. Miller046e26a2008-08-27 04:54:04 -0700447 portid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 (((error_bits & SYSIO_SBAFSR_PLE) ?
449 "Late PIO Error" :
450 ((error_bits & SYSIO_SBAFSR_PTO) ?
451 "Time Out" :
452 ((error_bits & SYSIO_SBAFSR_PBERR) ?
453 "Error Ack" : "???")))),
454 (afsr & SYSIO_SBAFSR_RD) ? 1 : 0);
455 printk("SYSIO[%x]: size[%lx] MID[%lx]\n",
David S. Miller046e26a2008-08-27 04:54:04 -0700456 portid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 (afsr & SYSIO_SBAFSR_SIZE) >> 42UL,
458 (afsr & SYSIO_SBAFSR_MID) >> 37UL);
David S. Miller046e26a2008-08-27 04:54:04 -0700459 printk("SYSIO[%x]: AFAR[%016lx]\n", portid, afar);
460 printk("SYSIO[%x]: Secondary SBUS errors [", portid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 reported = 0;
462 if (afsr & SYSIO_SBAFSR_SLE) {
463 reported++;
464 printk("(Late PIO Error)");
465 }
466 if (afsr & SYSIO_SBAFSR_STO) {
467 reported++;
468 printk("(Time Out)");
469 }
470 if (afsr & SYSIO_SBAFSR_SBERR) {
471 reported++;
472 printk("(Error Ack)");
473 }
474 if (!reported)
475 printk("(none)");
476 printk("]\n");
477
478 /* XXX check iommu/strbuf for further error status XXX */
479
480 return IRQ_HANDLED;
481}
482
483#define ECC_CONTROL 0x0020UL
484#define SYSIO_ECNTRL_ECCEN 0x8000000000000000UL /* Enable ECC Checking */
485#define SYSIO_ECNTRL_UEEN 0x4000000000000000UL /* Enable UE Interrupts */
486#define SYSIO_ECNTRL_CEEN 0x2000000000000000UL /* Enable CE Interrupts */
487
488#define SYSIO_UE_INO 0x34
489#define SYSIO_CE_INO 0x35
490#define SYSIO_SBUSERR_INO 0x36
491
Grant Likelycd4cd732010-07-22 16:04:30 -0600492static void __init sysio_register_error_handlers(struct platform_device *op)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493{
David S. Miller046e26a2008-08-27 04:54:04 -0700494 struct iommu *iommu = op->dev.archdata.iommu;
David S. Miller3e4d2652007-04-25 15:58:22 -0700495 unsigned long reg_base = iommu->write_complete_reg - 0x2000UL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 unsigned int irq;
497 u64 control;
David S. Miller046e26a2008-08-27 04:54:04 -0700498 int portid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499
Grant Likely61c7a082010-04-13 16:12:29 -0700500 portid = of_getintprop_default(op->dev.of_node, "portid", -1);
David S. Miller046e26a2008-08-27 04:54:04 -0700501
502 irq = sbus_build_irq(op, SYSIO_UE_INO);
David S. Miller96a496f2007-05-07 23:08:39 -0700503 if (request_irq(irq, sysio_ue_handler, 0,
David S. Miller046e26a2008-08-27 04:54:04 -0700504 "SYSIO_UE", op) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 prom_printf("SYSIO[%x]: Cannot register UE interrupt.\n",
David S. Miller046e26a2008-08-27 04:54:04 -0700506 portid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 prom_halt();
508 }
509
David S. Miller046e26a2008-08-27 04:54:04 -0700510 irq = sbus_build_irq(op, SYSIO_CE_INO);
David S. Miller96a496f2007-05-07 23:08:39 -0700511 if (request_irq(irq, sysio_ce_handler, 0,
David S. Miller046e26a2008-08-27 04:54:04 -0700512 "SYSIO_CE", op) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 prom_printf("SYSIO[%x]: Cannot register CE interrupt.\n",
David S. Miller046e26a2008-08-27 04:54:04 -0700514 portid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 prom_halt();
516 }
517
David S. Miller046e26a2008-08-27 04:54:04 -0700518 irq = sbus_build_irq(op, SYSIO_SBUSERR_INO);
David S. Miller96a496f2007-05-07 23:08:39 -0700519 if (request_irq(irq, sysio_sbus_error_handler, 0,
David S. Miller046e26a2008-08-27 04:54:04 -0700520 "SYSIO_SBERR", op) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 prom_printf("SYSIO[%x]: Cannot register SBUS Error interrupt.\n",
David S. Miller046e26a2008-08-27 04:54:04 -0700522 portid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 prom_halt();
524 }
525
526 /* Now turn the error interrupts on and also enable ECC checking. */
527 upa_writeq((SYSIO_ECNTRL_ECCEN |
528 SYSIO_ECNTRL_UEEN |
529 SYSIO_ECNTRL_CEEN),
530 reg_base + ECC_CONTROL);
531
David S. Miller3e4d2652007-04-25 15:58:22 -0700532 control = upa_readq(iommu->write_complete_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 control |= 0x100UL; /* SBUS Error Interrupt Enable */
David S. Miller3e4d2652007-04-25 15:58:22 -0700534 upa_writeq(control, iommu->write_complete_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535}
536
537/* Boot time initialization. */
Grant Likelycd4cd732010-07-22 16:04:30 -0600538static void __init sbus_iommu_init(struct platform_device *op)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539{
Stephen Rothwell6a23acf2007-04-23 15:53:27 -0700540 const struct linux_prom64_registers *pr;
Grant Likely61c7a082010-04-13 16:12:29 -0700541 struct device_node *dp = op->dev.of_node;
David S. Miller3e4d2652007-04-25 15:58:22 -0700542 struct iommu *iommu;
543 struct strbuf *strbuf;
544 unsigned long regs, reg_base;
David S. Miller046e26a2008-08-27 04:54:04 -0700545 int i, portid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 u64 control;
David S. Miller25c75812006-06-22 20:21:22 -0700547
548 pr = of_get_property(dp, "reg", NULL);
549 if (!pr) {
David S. Millerad7ad572007-07-27 22:39:14 -0700550 prom_printf("sbus_iommu_init: Cannot map SYSIO "
551 "control registers.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 prom_halt();
553 }
David S. Miller25c75812006-06-22 20:21:22 -0700554 regs = pr->phys_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
David S. Millerad7ad572007-07-27 22:39:14 -0700556 iommu = kzalloc(sizeof(*iommu), GFP_ATOMIC);
David S. Millerad7ad572007-07-27 22:39:14 -0700557 strbuf = kzalloc(sizeof(*strbuf), GFP_ATOMIC);
Cong Ding04cef492013-01-17 03:28:43 +0000558 if (!iommu || !strbuf)
David S. Millerad7ad572007-07-27 22:39:14 -0700559 goto fatal_memory_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560
David S. Miller046e26a2008-08-27 04:54:04 -0700561 op->dev.archdata.iommu = iommu;
562 op->dev.archdata.stc = strbuf;
563 op->dev.archdata.numa_node = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564
David S. Miller3e4d2652007-04-25 15:58:22 -0700565 reg_base = regs + SYSIO_IOMMUREG_BASE;
566 iommu->iommu_control = reg_base + IOMMU_CONTROL;
567 iommu->iommu_tsbbase = reg_base + IOMMU_TSBBASE;
568 iommu->iommu_flush = reg_base + IOMMU_FLUSH;
David S. Millerad7ad572007-07-27 22:39:14 -0700569 iommu->iommu_tags = iommu->iommu_control +
570 (IOMMU_TAGDIAG - IOMMU_CONTROL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571
David S. Miller3e4d2652007-04-25 15:58:22 -0700572 reg_base = regs + SYSIO_STRBUFREG_BASE;
573 strbuf->strbuf_control = reg_base + STRBUF_CONTROL;
574 strbuf->strbuf_pflush = reg_base + STRBUF_PFLUSH;
575 strbuf->strbuf_fsync = reg_base + STRBUF_FSYNC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576
David S. Miller3e4d2652007-04-25 15:58:22 -0700577 strbuf->strbuf_enabled = 1;
578
579 strbuf->strbuf_flushflag = (volatile unsigned long *)
580 ((((unsigned long)&strbuf->__flushflag_buf[0])
581 + 63UL)
582 & ~63UL);
583 strbuf->strbuf_flushflag_pa = (unsigned long)
584 __pa(strbuf->strbuf_flushflag);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585
586 /* The SYSIO SBUS control register is used for dummy reads
587 * in order to ensure write completion.
588 */
David S. Miller3e4d2652007-04-25 15:58:22 -0700589 iommu->write_complete_reg = regs + 0x2000UL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590
Grant Likely61c7a082010-04-13 16:12:29 -0700591 portid = of_getintprop_default(op->dev.of_node, "portid", -1);
David S. Miller046e26a2008-08-27 04:54:04 -0700592 printk(KERN_INFO "SYSIO: UPA portID %x, at %016lx\n",
593 portid, regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594
595 /* Setup for TSB_SIZE=7, TBW_SIZE=0, MMU_DE=1, MMU_EN=1 */
David S. Millerc1b1a5f2008-03-19 04:52:48 -0700596 if (iommu_table_init(iommu, IO_TSB_SIZE, MAP_BASE, 0xffffffff, -1))
David S. Millerad7ad572007-07-27 22:39:14 -0700597 goto fatal_memory_error;
David S. Miller2f3a2ef2007-04-11 21:38:45 -0700598
David S. Miller3e4d2652007-04-25 15:58:22 -0700599 control = upa_readq(iommu->iommu_control);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 control = ((7UL << 16UL) |
601 (0UL << 2UL) |
602 (1UL << 1UL) |
603 (1UL << 0UL));
David S. Miller3e4d2652007-04-25 15:58:22 -0700604 upa_writeq(control, iommu->iommu_control);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605
606 /* Clean out any cruft in the IOMMU using
607 * diagnostic accesses.
608 */
609 for (i = 0; i < 16; i++) {
David S. Miller3e4d2652007-04-25 15:58:22 -0700610 unsigned long dram, tag;
611
612 dram = iommu->iommu_control + (IOMMU_DRAMDIAG - IOMMU_CONTROL);
613 tag = iommu->iommu_control + (IOMMU_TAGDIAG - IOMMU_CONTROL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614
615 dram += (unsigned long)i * 8UL;
616 tag += (unsigned long)i * 8UL;
617 upa_writeq(0, dram);
618 upa_writeq(0, tag);
619 }
David S. Miller3e4d2652007-04-25 15:58:22 -0700620 upa_readq(iommu->write_complete_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621
622 /* Give the TSB to SYSIO. */
David S. Miller3e4d2652007-04-25 15:58:22 -0700623 upa_writeq(__pa(iommu->page_table), iommu->iommu_tsbbase);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624
625 /* Setup streaming buffer, DE=1 SB_EN=1 */
626 control = (1UL << 1UL) | (1UL << 0UL);
David S. Miller3e4d2652007-04-25 15:58:22 -0700627 upa_writeq(control, strbuf->strbuf_control);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628
629 /* Clear out the tags using diagnostics. */
630 for (i = 0; i < 16; i++) {
631 unsigned long ptag, ltag;
632
David S. Miller3e4d2652007-04-25 15:58:22 -0700633 ptag = strbuf->strbuf_control +
634 (STRBUF_PTAGDIAG - STRBUF_CONTROL);
635 ltag = strbuf->strbuf_control +
636 (STRBUF_LTAGDIAG - STRBUF_CONTROL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 ptag += (unsigned long)i * 8UL;
638 ltag += (unsigned long)i * 8UL;
639
640 upa_writeq(0UL, ptag);
641 upa_writeq(0UL, ltag);
642 }
643
644 /* Enable DVMA arbitration for all devices/slots. */
David S. Miller3e4d2652007-04-25 15:58:22 -0700645 control = upa_readq(iommu->write_complete_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 control |= 0x3fUL;
David S. Miller3e4d2652007-04-25 15:58:22 -0700647 upa_writeq(control, iommu->write_complete_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648
649 /* Now some Xfire specific grot... */
650 if (this_is_starfire)
David S. Miller046e26a2008-08-27 04:54:04 -0700651 starfire_hookup(portid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652
David S. Miller046e26a2008-08-27 04:54:04 -0700653 sysio_register_error_handlers(op);
David S. Millerad7ad572007-07-27 22:39:14 -0700654 return;
655
656fatal_memory_error:
Cong Ding04cef492013-01-17 03:28:43 +0000657 kfree(iommu);
658 kfree(strbuf);
David S. Millerad7ad572007-07-27 22:39:14 -0700659 prom_printf("sbus_iommu_init: Fatal memory allocation error.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660}
David S. Miller8fae0972006-06-20 15:23:28 -0700661
David S. Miller046e26a2008-08-27 04:54:04 -0700662static int __init sbus_init(void)
David S. Miller576c3522006-06-23 15:55:45 -0700663{
David S. Miller046e26a2008-08-27 04:54:04 -0700664 struct device_node *dp;
665
666 for_each_node_by_name(dp, "sbus") {
Grant Likelycd4cd732010-07-22 16:04:30 -0600667 struct platform_device *op = of_find_device_by_node(dp);
David S. Miller046e26a2008-08-27 04:54:04 -0700668
669 sbus_iommu_init(op);
670 of_propagate_archdata(op);
671 }
David S. Miller576c3522006-06-23 15:55:45 -0700672
David S. Miller046e26a2008-08-27 04:54:04 -0700673 return 0;
David S. Miller576c3522006-06-23 15:55:45 -0700674}
David S. Miller046e26a2008-08-27 04:54:04 -0700675
676subsys_initcall(sbus_init);