Adrian Bunk | b00dc83 | 2008-05-19 16:52:27 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * 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> |
David S. Miller | 9dc6923 | 2008-08-27 19:54:01 -0700 | [diff] [blame] | 14 | #include <linux/of.h> |
| 15 | #include <linux/of_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | |
| 17 | #include <asm/page.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <asm/io.h> |
| 19 | #include <asm/upa.h> |
| 20 | #include <asm/cache.h> |
| 21 | #include <asm/dma.h> |
| 22 | #include <asm/irq.h> |
David S. Miller | 25c7581 | 2006-06-22 20:21:22 -0700 | [diff] [blame] | 23 | #include <asm/prom.h> |
David S. Miller | 9dc6923 | 2008-08-27 19:54:01 -0700 | [diff] [blame] | 24 | #include <asm/oplib.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <asm/starfire.h> |
| 26 | |
| 27 | #include "iommu_common.h" |
| 28 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #define MAP_BASE ((u32)0xc0000000) |
| 30 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | /* Offsets from iommu_regs */ |
| 32 | #define SYSIO_IOMMUREG_BASE 0x2400UL |
| 33 | #define IOMMU_CONTROL (0x2400UL - 0x2400UL) /* IOMMU control register */ |
| 34 | #define IOMMU_TSBBASE (0x2408UL - 0x2400UL) /* TSB base address register */ |
| 35 | #define IOMMU_FLUSH (0x2410UL - 0x2400UL) /* IOMMU flush register */ |
| 36 | #define IOMMU_VADIAG (0x4400UL - 0x2400UL) /* SBUS virtual address diagnostic */ |
| 37 | #define IOMMU_TAGCMP (0x4408UL - 0x2400UL) /* TLB tag compare diagnostics */ |
| 38 | #define IOMMU_LRUDIAG (0x4500UL - 0x2400UL) /* IOMMU LRU queue diagnostics */ |
| 39 | #define IOMMU_TAGDIAG (0x4580UL - 0x2400UL) /* TLB tag diagnostics */ |
| 40 | #define IOMMU_DRAMDIAG (0x4600UL - 0x2400UL) /* TLB data RAM diagnostics */ |
| 41 | |
| 42 | #define IOMMU_DRAM_VALID (1UL << 30UL) |
| 43 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | /* Offsets from strbuf_regs */ |
| 45 | #define SYSIO_STRBUFREG_BASE 0x2800UL |
| 46 | #define STRBUF_CONTROL (0x2800UL - 0x2800UL) /* Control */ |
| 47 | #define STRBUF_PFLUSH (0x2808UL - 0x2800UL) /* Page flush/invalidate */ |
| 48 | #define STRBUF_FSYNC (0x2810UL - 0x2800UL) /* Flush synchronization */ |
| 49 | #define STRBUF_DRAMDIAG (0x5000UL - 0x2800UL) /* data RAM diagnostic */ |
| 50 | #define STRBUF_ERRDIAG (0x5400UL - 0x2800UL) /* error status diagnostics */ |
| 51 | #define STRBUF_PTAGDIAG (0x5800UL - 0x2800UL) /* Page tag diagnostics */ |
| 52 | #define STRBUF_LTAGDIAG (0x5900UL - 0x2800UL) /* Line tag diagnostics */ |
| 53 | |
| 54 | #define STRBUF_TAG_VALID 0x02UL |
| 55 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | /* Enable 64-bit DVMA mode for the given device. */ |
David S. Miller | 63237ee | 2008-08-26 23:33:42 -0700 | [diff] [blame] | 57 | void sbus_set_sbus64(struct device *dev, int bursts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | { |
David S. Miller | 63237ee | 2008-08-26 23:33:42 -0700 | [diff] [blame] | 59 | struct iommu *iommu = dev->archdata.iommu; |
Grant Likely | cd4cd73 | 2010-07-22 16:04:30 -0600 | [diff] [blame] | 60 | struct platform_device *op = to_platform_device(dev); |
David S. Miller | 63237ee | 2008-08-26 23:33:42 -0700 | [diff] [blame] | 61 | const struct linux_prom_registers *regs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | unsigned long cfg_reg; |
David S. Miller | 63237ee | 2008-08-26 23:33:42 -0700 | [diff] [blame] | 63 | int slot; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | u64 val; |
| 65 | |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 66 | regs = of_get_property(op->dev.of_node, "reg", NULL); |
David S. Miller | 63237ee | 2008-08-26 23:33:42 -0700 | [diff] [blame] | 67 | if (!regs) { |
| 68 | printk(KERN_ERR "sbus_set_sbus64: Cannot find regs for %s\n", |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 69 | op->dev.of_node->full_name); |
David S. Miller | 63237ee | 2008-08-26 23:33:42 -0700 | [diff] [blame] | 70 | return; |
| 71 | } |
| 72 | slot = regs->which_io; |
| 73 | |
David S. Miller | 3e4d265 | 2007-04-25 15:58:22 -0700 | [diff] [blame] | 74 | cfg_reg = iommu->write_complete_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | switch (slot) { |
| 76 | case 0: |
| 77 | cfg_reg += 0x20UL; |
| 78 | break; |
| 79 | case 1: |
| 80 | cfg_reg += 0x28UL; |
| 81 | break; |
| 82 | case 2: |
| 83 | cfg_reg += 0x30UL; |
| 84 | break; |
| 85 | case 3: |
| 86 | cfg_reg += 0x38UL; |
| 87 | break; |
| 88 | case 13: |
| 89 | cfg_reg += 0x40UL; |
| 90 | break; |
| 91 | case 14: |
| 92 | cfg_reg += 0x48UL; |
| 93 | break; |
| 94 | case 15: |
| 95 | cfg_reg += 0x50UL; |
| 96 | break; |
| 97 | |
| 98 | default: |
| 99 | return; |
Joe Perches | 6cb79b3 | 2011-06-03 14:45:23 +0000 | [diff] [blame^] | 100 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | |
| 102 | val = upa_readq(cfg_reg); |
| 103 | if (val & (1UL << 14UL)) { |
| 104 | /* Extended transfer mode already enabled. */ |
| 105 | return; |
| 106 | } |
| 107 | |
| 108 | val |= (1UL << 14UL); |
| 109 | |
| 110 | if (bursts & DMA_BURST8) |
| 111 | val |= (1UL << 1UL); |
| 112 | if (bursts & DMA_BURST16) |
| 113 | val |= (1UL << 2UL); |
| 114 | if (bursts & DMA_BURST32) |
| 115 | val |= (1UL << 3UL); |
| 116 | if (bursts & DMA_BURST64) |
| 117 | val |= (1UL << 4UL); |
| 118 | upa_writeq(val, cfg_reg); |
| 119 | } |
Sam Ravnborg | 917c366 | 2009-01-08 16:58:20 -0800 | [diff] [blame] | 120 | EXPORT_SYMBOL(sbus_set_sbus64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | /* INO number to IMAP register offset for SYSIO external IRQ's. |
| 123 | * This should conform to both Sunfire/Wildfire server and Fusion |
| 124 | * desktop designs. |
| 125 | */ |
David S. Miller | ec4d18f | 2007-06-07 16:58:22 -0700 | [diff] [blame] | 126 | #define SYSIO_IMAP_SLOT0 0x2c00UL |
| 127 | #define SYSIO_IMAP_SLOT1 0x2c08UL |
| 128 | #define SYSIO_IMAP_SLOT2 0x2c10UL |
| 129 | #define SYSIO_IMAP_SLOT3 0x2c18UL |
| 130 | #define SYSIO_IMAP_SCSI 0x3000UL |
| 131 | #define SYSIO_IMAP_ETH 0x3008UL |
| 132 | #define SYSIO_IMAP_BPP 0x3010UL |
| 133 | #define SYSIO_IMAP_AUDIO 0x3018UL |
| 134 | #define SYSIO_IMAP_PFAIL 0x3020UL |
| 135 | #define SYSIO_IMAP_KMS 0x3028UL |
| 136 | #define SYSIO_IMAP_FLPY 0x3030UL |
| 137 | #define SYSIO_IMAP_SHW 0x3038UL |
| 138 | #define SYSIO_IMAP_KBD 0x3040UL |
| 139 | #define SYSIO_IMAP_MS 0x3048UL |
| 140 | #define SYSIO_IMAP_SER 0x3050UL |
| 141 | #define SYSIO_IMAP_TIM0 0x3060UL |
| 142 | #define SYSIO_IMAP_TIM1 0x3068UL |
| 143 | #define SYSIO_IMAP_UE 0x3070UL |
| 144 | #define SYSIO_IMAP_CE 0x3078UL |
| 145 | #define SYSIO_IMAP_SBERR 0x3080UL |
| 146 | #define SYSIO_IMAP_PMGMT 0x3088UL |
| 147 | #define SYSIO_IMAP_GFX 0x3090UL |
| 148 | #define SYSIO_IMAP_EUPA 0x3098UL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | |
| 150 | #define bogon ((unsigned long) -1) |
| 151 | static unsigned long sysio_irq_offsets[] = { |
| 152 | /* SBUS Slot 0 --> 3, level 1 --> 7 */ |
| 153 | SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0, |
| 154 | SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0, |
| 155 | SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1, |
| 156 | SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1, |
| 157 | SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2, |
| 158 | SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2, |
| 159 | SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3, |
| 160 | SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3, |
| 161 | |
| 162 | /* Onboard devices (not relevant/used on SunFire). */ |
| 163 | SYSIO_IMAP_SCSI, |
| 164 | SYSIO_IMAP_ETH, |
| 165 | SYSIO_IMAP_BPP, |
| 166 | bogon, |
| 167 | SYSIO_IMAP_AUDIO, |
| 168 | SYSIO_IMAP_PFAIL, |
| 169 | bogon, |
| 170 | bogon, |
| 171 | SYSIO_IMAP_KMS, |
| 172 | SYSIO_IMAP_FLPY, |
| 173 | SYSIO_IMAP_SHW, |
| 174 | SYSIO_IMAP_KBD, |
| 175 | SYSIO_IMAP_MS, |
| 176 | SYSIO_IMAP_SER, |
| 177 | bogon, |
| 178 | bogon, |
| 179 | SYSIO_IMAP_TIM0, |
| 180 | SYSIO_IMAP_TIM1, |
| 181 | bogon, |
| 182 | bogon, |
| 183 | SYSIO_IMAP_UE, |
| 184 | SYSIO_IMAP_CE, |
| 185 | SYSIO_IMAP_SBERR, |
| 186 | SYSIO_IMAP_PMGMT, |
| 187 | }; |
| 188 | |
| 189 | #undef bogon |
| 190 | |
Tobias Klauser | 84c1a13 | 2005-11-09 12:03:42 -0800 | [diff] [blame] | 191 | #define NUM_SYSIO_OFFSETS ARRAY_SIZE(sysio_irq_offsets) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | |
| 193 | /* Convert Interrupt Mapping register pointer to associated |
| 194 | * Interrupt Clear register pointer, SYSIO specific version. |
| 195 | */ |
| 196 | #define SYSIO_ICLR_UNUSED0 0x3400UL |
David S. Miller | ec4d18f | 2007-06-07 16:58:22 -0700 | [diff] [blame] | 197 | #define SYSIO_ICLR_SLOT0 0x3408UL |
| 198 | #define SYSIO_ICLR_SLOT1 0x3448UL |
| 199 | #define SYSIO_ICLR_SLOT2 0x3488UL |
| 200 | #define SYSIO_ICLR_SLOT3 0x34c8UL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | static unsigned long sysio_imap_to_iclr(unsigned long imap) |
| 202 | { |
| 203 | unsigned long diff = SYSIO_ICLR_UNUSED0 - SYSIO_IMAP_SLOT0; |
| 204 | return imap + diff; |
| 205 | } |
| 206 | |
Grant Likely | cd4cd73 | 2010-07-22 16:04:30 -0600 | [diff] [blame] | 207 | static unsigned int sbus_build_irq(struct platform_device *op, unsigned int ino) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | { |
David S. Miller | 046e26a | 2008-08-27 04:54:04 -0700 | [diff] [blame] | 209 | struct iommu *iommu = op->dev.archdata.iommu; |
David S. Miller | 3e4d265 | 2007-04-25 15:58:22 -0700 | [diff] [blame] | 210 | unsigned long reg_base = iommu->write_complete_reg - 0x2000UL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | unsigned long imap, iclr; |
David S. Miller | 37cdcd9 | 2006-06-20 01:21:57 -0700 | [diff] [blame] | 212 | int sbus_level = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | |
| 214 | imap = sysio_irq_offsets[ino]; |
| 215 | if (imap == ((unsigned long)-1)) { |
David S. Miller | 37cdcd9 | 2006-06-20 01:21:57 -0700 | [diff] [blame] | 216 | prom_printf("get_irq_translations: Bad SYSIO INO[%x]\n", |
| 217 | ino); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | prom_halt(); |
| 219 | } |
| 220 | imap += reg_base; |
| 221 | |
| 222 | /* SYSIO inconsistency. For external SLOTS, we have to select |
| 223 | * the right ICLR register based upon the lower SBUS irq level |
| 224 | * bits. |
| 225 | */ |
| 226 | if (ino >= 0x20) { |
| 227 | iclr = sysio_imap_to_iclr(imap); |
| 228 | } else { |
| 229 | int sbus_slot = (ino & 0x18)>>3; |
| 230 | |
| 231 | sbus_level = ino & 0x7; |
| 232 | |
| 233 | switch(sbus_slot) { |
| 234 | case 0: |
| 235 | iclr = reg_base + SYSIO_ICLR_SLOT0; |
| 236 | break; |
| 237 | case 1: |
| 238 | iclr = reg_base + SYSIO_ICLR_SLOT1; |
| 239 | break; |
| 240 | case 2: |
| 241 | iclr = reg_base + SYSIO_ICLR_SLOT2; |
| 242 | break; |
| 243 | default: |
| 244 | case 3: |
| 245 | iclr = reg_base + SYSIO_ICLR_SLOT3; |
| 246 | break; |
Joe Perches | 6cb79b3 | 2011-06-03 14:45:23 +0000 | [diff] [blame^] | 247 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | |
| 249 | iclr += ((unsigned long)sbus_level - 1UL) * 8UL; |
| 250 | } |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 251 | return build_irq(sbus_level, iclr, imap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | /* Error interrupt handling. */ |
| 255 | #define SYSIO_UE_AFSR 0x0030UL |
| 256 | #define SYSIO_UE_AFAR 0x0038UL |
| 257 | #define SYSIO_UEAFSR_PPIO 0x8000000000000000UL /* Primary PIO cause */ |
| 258 | #define SYSIO_UEAFSR_PDRD 0x4000000000000000UL /* Primary DVMA read cause */ |
| 259 | #define SYSIO_UEAFSR_PDWR 0x2000000000000000UL /* Primary DVMA write cause */ |
| 260 | #define SYSIO_UEAFSR_SPIO 0x1000000000000000UL /* Secondary PIO is cause */ |
| 261 | #define SYSIO_UEAFSR_SDRD 0x0800000000000000UL /* Secondary DVMA read cause */ |
| 262 | #define SYSIO_UEAFSR_SDWR 0x0400000000000000UL /* Secondary DVMA write cause*/ |
| 263 | #define SYSIO_UEAFSR_RESV1 0x03ff000000000000UL /* Reserved */ |
| 264 | #define SYSIO_UEAFSR_DOFF 0x0000e00000000000UL /* Doubleword Offset */ |
| 265 | #define SYSIO_UEAFSR_SIZE 0x00001c0000000000UL /* Bad transfer size 2^SIZE */ |
| 266 | #define SYSIO_UEAFSR_MID 0x000003e000000000UL /* UPA MID causing the fault */ |
| 267 | #define SYSIO_UEAFSR_RESV2 0x0000001fffffffffUL /* Reserved */ |
Al Viro | 6d24c8d | 2006-10-08 08:23:28 -0400 | [diff] [blame] | 268 | static irqreturn_t sysio_ue_handler(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | { |
Grant Likely | cd4cd73 | 2010-07-22 16:04:30 -0600 | [diff] [blame] | 270 | struct platform_device *op = dev_id; |
David S. Miller | 046e26a | 2008-08-27 04:54:04 -0700 | [diff] [blame] | 271 | struct iommu *iommu = op->dev.archdata.iommu; |
David S. Miller | 3e4d265 | 2007-04-25 15:58:22 -0700 | [diff] [blame] | 272 | unsigned long reg_base = iommu->write_complete_reg - 0x2000UL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | unsigned long afsr_reg, afar_reg; |
| 274 | unsigned long afsr, afar, error_bits; |
David S. Miller | 046e26a | 2008-08-27 04:54:04 -0700 | [diff] [blame] | 275 | int reported, portid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | |
| 277 | afsr_reg = reg_base + SYSIO_UE_AFSR; |
| 278 | afar_reg = reg_base + SYSIO_UE_AFAR; |
| 279 | |
| 280 | /* Latch error status. */ |
| 281 | afsr = upa_readq(afsr_reg); |
| 282 | afar = upa_readq(afar_reg); |
| 283 | |
| 284 | /* Clear primary/secondary error status bits. */ |
| 285 | error_bits = afsr & |
| 286 | (SYSIO_UEAFSR_PPIO | SYSIO_UEAFSR_PDRD | SYSIO_UEAFSR_PDWR | |
| 287 | SYSIO_UEAFSR_SPIO | SYSIO_UEAFSR_SDRD | SYSIO_UEAFSR_SDWR); |
| 288 | upa_writeq(error_bits, afsr_reg); |
| 289 | |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 290 | portid = of_getintprop_default(op->dev.of_node, "portid", -1); |
David S. Miller | 046e26a | 2008-08-27 04:54:04 -0700 | [diff] [blame] | 291 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | /* Log the error. */ |
| 293 | printk("SYSIO[%x]: Uncorrectable ECC Error, primary error type[%s]\n", |
David S. Miller | 046e26a | 2008-08-27 04:54:04 -0700 | [diff] [blame] | 294 | portid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | (((error_bits & SYSIO_UEAFSR_PPIO) ? |
| 296 | "PIO" : |
| 297 | ((error_bits & SYSIO_UEAFSR_PDRD) ? |
| 298 | "DVMA Read" : |
| 299 | ((error_bits & SYSIO_UEAFSR_PDWR) ? |
| 300 | "DVMA Write" : "???"))))); |
| 301 | printk("SYSIO[%x]: DOFF[%lx] SIZE[%lx] MID[%lx]\n", |
David S. Miller | 046e26a | 2008-08-27 04:54:04 -0700 | [diff] [blame] | 302 | portid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | (afsr & SYSIO_UEAFSR_DOFF) >> 45UL, |
| 304 | (afsr & SYSIO_UEAFSR_SIZE) >> 42UL, |
| 305 | (afsr & SYSIO_UEAFSR_MID) >> 37UL); |
David S. Miller | 046e26a | 2008-08-27 04:54:04 -0700 | [diff] [blame] | 306 | printk("SYSIO[%x]: AFAR[%016lx]\n", portid, afar); |
| 307 | printk("SYSIO[%x]: Secondary UE errors [", portid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | reported = 0; |
| 309 | if (afsr & SYSIO_UEAFSR_SPIO) { |
| 310 | reported++; |
| 311 | printk("(PIO)"); |
| 312 | } |
| 313 | if (afsr & SYSIO_UEAFSR_SDRD) { |
| 314 | reported++; |
| 315 | printk("(DVMA Read)"); |
| 316 | } |
| 317 | if (afsr & SYSIO_UEAFSR_SDWR) { |
| 318 | reported++; |
| 319 | printk("(DVMA Write)"); |
| 320 | } |
| 321 | if (!reported) |
| 322 | printk("(none)"); |
| 323 | printk("]\n"); |
| 324 | |
| 325 | return IRQ_HANDLED; |
| 326 | } |
| 327 | |
| 328 | #define SYSIO_CE_AFSR 0x0040UL |
| 329 | #define SYSIO_CE_AFAR 0x0048UL |
| 330 | #define SYSIO_CEAFSR_PPIO 0x8000000000000000UL /* Primary PIO cause */ |
| 331 | #define SYSIO_CEAFSR_PDRD 0x4000000000000000UL /* Primary DVMA read cause */ |
| 332 | #define SYSIO_CEAFSR_PDWR 0x2000000000000000UL /* Primary DVMA write cause */ |
| 333 | #define SYSIO_CEAFSR_SPIO 0x1000000000000000UL /* Secondary PIO cause */ |
| 334 | #define SYSIO_CEAFSR_SDRD 0x0800000000000000UL /* Secondary DVMA read cause */ |
| 335 | #define SYSIO_CEAFSR_SDWR 0x0400000000000000UL /* Secondary DVMA write cause*/ |
| 336 | #define SYSIO_CEAFSR_RESV1 0x0300000000000000UL /* Reserved */ |
| 337 | #define SYSIO_CEAFSR_ESYND 0x00ff000000000000UL /* Syndrome Bits */ |
| 338 | #define SYSIO_CEAFSR_DOFF 0x0000e00000000000UL /* Double Offset */ |
| 339 | #define SYSIO_CEAFSR_SIZE 0x00001c0000000000UL /* Bad transfer size 2^SIZE */ |
| 340 | #define SYSIO_CEAFSR_MID 0x000003e000000000UL /* UPA MID causing the fault */ |
| 341 | #define SYSIO_CEAFSR_RESV2 0x0000001fffffffffUL /* Reserved */ |
Al Viro | 6d24c8d | 2006-10-08 08:23:28 -0400 | [diff] [blame] | 342 | static irqreturn_t sysio_ce_handler(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | { |
Grant Likely | cd4cd73 | 2010-07-22 16:04:30 -0600 | [diff] [blame] | 344 | struct platform_device *op = dev_id; |
David S. Miller | 046e26a | 2008-08-27 04:54:04 -0700 | [diff] [blame] | 345 | struct iommu *iommu = op->dev.archdata.iommu; |
David S. Miller | 3e4d265 | 2007-04-25 15:58:22 -0700 | [diff] [blame] | 346 | unsigned long reg_base = iommu->write_complete_reg - 0x2000UL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | unsigned long afsr_reg, afar_reg; |
| 348 | unsigned long afsr, afar, error_bits; |
David S. Miller | 046e26a | 2008-08-27 04:54:04 -0700 | [diff] [blame] | 349 | int reported, portid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | |
| 351 | afsr_reg = reg_base + SYSIO_CE_AFSR; |
| 352 | afar_reg = reg_base + SYSIO_CE_AFAR; |
| 353 | |
| 354 | /* Latch error status. */ |
| 355 | afsr = upa_readq(afsr_reg); |
| 356 | afar = upa_readq(afar_reg); |
| 357 | |
| 358 | /* Clear primary/secondary error status bits. */ |
| 359 | error_bits = afsr & |
| 360 | (SYSIO_CEAFSR_PPIO | SYSIO_CEAFSR_PDRD | SYSIO_CEAFSR_PDWR | |
| 361 | SYSIO_CEAFSR_SPIO | SYSIO_CEAFSR_SDRD | SYSIO_CEAFSR_SDWR); |
| 362 | upa_writeq(error_bits, afsr_reg); |
| 363 | |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 364 | portid = of_getintprop_default(op->dev.of_node, "portid", -1); |
David S. Miller | 046e26a | 2008-08-27 04:54:04 -0700 | [diff] [blame] | 365 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | printk("SYSIO[%x]: Correctable ECC Error, primary error type[%s]\n", |
David S. Miller | 046e26a | 2008-08-27 04:54:04 -0700 | [diff] [blame] | 367 | portid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | (((error_bits & SYSIO_CEAFSR_PPIO) ? |
| 369 | "PIO" : |
| 370 | ((error_bits & SYSIO_CEAFSR_PDRD) ? |
| 371 | "DVMA Read" : |
| 372 | ((error_bits & SYSIO_CEAFSR_PDWR) ? |
| 373 | "DVMA Write" : "???"))))); |
| 374 | |
| 375 | /* XXX Use syndrome and afar to print out module string just like |
| 376 | * XXX UDB CE trap handler does... -DaveM |
| 377 | */ |
| 378 | printk("SYSIO[%x]: DOFF[%lx] ECC Syndrome[%lx] Size[%lx] MID[%lx]\n", |
David S. Miller | 046e26a | 2008-08-27 04:54:04 -0700 | [diff] [blame] | 379 | portid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | (afsr & SYSIO_CEAFSR_DOFF) >> 45UL, |
| 381 | (afsr & SYSIO_CEAFSR_ESYND) >> 48UL, |
| 382 | (afsr & SYSIO_CEAFSR_SIZE) >> 42UL, |
| 383 | (afsr & SYSIO_CEAFSR_MID) >> 37UL); |
David S. Miller | 046e26a | 2008-08-27 04:54:04 -0700 | [diff] [blame] | 384 | printk("SYSIO[%x]: AFAR[%016lx]\n", portid, afar); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | |
David S. Miller | 046e26a | 2008-08-27 04:54:04 -0700 | [diff] [blame] | 386 | printk("SYSIO[%x]: Secondary CE errors [", portid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | reported = 0; |
| 388 | if (afsr & SYSIO_CEAFSR_SPIO) { |
| 389 | reported++; |
| 390 | printk("(PIO)"); |
| 391 | } |
| 392 | if (afsr & SYSIO_CEAFSR_SDRD) { |
| 393 | reported++; |
| 394 | printk("(DVMA Read)"); |
| 395 | } |
| 396 | if (afsr & SYSIO_CEAFSR_SDWR) { |
| 397 | reported++; |
| 398 | printk("(DVMA Write)"); |
| 399 | } |
| 400 | if (!reported) |
| 401 | printk("(none)"); |
| 402 | printk("]\n"); |
| 403 | |
| 404 | return IRQ_HANDLED; |
| 405 | } |
| 406 | |
| 407 | #define SYSIO_SBUS_AFSR 0x2010UL |
| 408 | #define SYSIO_SBUS_AFAR 0x2018UL |
| 409 | #define SYSIO_SBAFSR_PLE 0x8000000000000000UL /* Primary Late PIO Error */ |
| 410 | #define SYSIO_SBAFSR_PTO 0x4000000000000000UL /* Primary SBUS Timeout */ |
| 411 | #define SYSIO_SBAFSR_PBERR 0x2000000000000000UL /* Primary SBUS Error ACK */ |
| 412 | #define SYSIO_SBAFSR_SLE 0x1000000000000000UL /* Secondary Late PIO Error */ |
| 413 | #define SYSIO_SBAFSR_STO 0x0800000000000000UL /* Secondary SBUS Timeout */ |
| 414 | #define SYSIO_SBAFSR_SBERR 0x0400000000000000UL /* Secondary SBUS Error ACK */ |
| 415 | #define SYSIO_SBAFSR_RESV1 0x03ff000000000000UL /* Reserved */ |
| 416 | #define SYSIO_SBAFSR_RD 0x0000800000000000UL /* Primary was late PIO read */ |
| 417 | #define SYSIO_SBAFSR_RESV2 0x0000600000000000UL /* Reserved */ |
| 418 | #define SYSIO_SBAFSR_SIZE 0x00001c0000000000UL /* Size of transfer */ |
| 419 | #define SYSIO_SBAFSR_MID 0x000003e000000000UL /* MID causing the error */ |
| 420 | #define SYSIO_SBAFSR_RESV3 0x0000001fffffffffUL /* Reserved */ |
Al Viro | 6d24c8d | 2006-10-08 08:23:28 -0400 | [diff] [blame] | 421 | static irqreturn_t sysio_sbus_error_handler(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | { |
Grant Likely | cd4cd73 | 2010-07-22 16:04:30 -0600 | [diff] [blame] | 423 | struct platform_device *op = dev_id; |
David S. Miller | 046e26a | 2008-08-27 04:54:04 -0700 | [diff] [blame] | 424 | struct iommu *iommu = op->dev.archdata.iommu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | unsigned long afsr_reg, afar_reg, reg_base; |
| 426 | unsigned long afsr, afar, error_bits; |
David S. Miller | 046e26a | 2008-08-27 04:54:04 -0700 | [diff] [blame] | 427 | int reported, portid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | |
David S. Miller | 3e4d265 | 2007-04-25 15:58:22 -0700 | [diff] [blame] | 429 | reg_base = iommu->write_complete_reg - 0x2000UL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | afsr_reg = reg_base + SYSIO_SBUS_AFSR; |
| 431 | afar_reg = reg_base + SYSIO_SBUS_AFAR; |
| 432 | |
| 433 | afsr = upa_readq(afsr_reg); |
| 434 | afar = upa_readq(afar_reg); |
| 435 | |
| 436 | /* Clear primary/secondary error status bits. */ |
| 437 | error_bits = afsr & |
| 438 | (SYSIO_SBAFSR_PLE | SYSIO_SBAFSR_PTO | SYSIO_SBAFSR_PBERR | |
| 439 | SYSIO_SBAFSR_SLE | SYSIO_SBAFSR_STO | SYSIO_SBAFSR_SBERR); |
| 440 | upa_writeq(error_bits, afsr_reg); |
| 441 | |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 442 | portid = of_getintprop_default(op->dev.of_node, "portid", -1); |
David S. Miller | 046e26a | 2008-08-27 04:54:04 -0700 | [diff] [blame] | 443 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | /* Log the error. */ |
| 445 | printk("SYSIO[%x]: SBUS Error, primary error type[%s] read(%d)\n", |
David S. Miller | 046e26a | 2008-08-27 04:54:04 -0700 | [diff] [blame] | 446 | portid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | (((error_bits & SYSIO_SBAFSR_PLE) ? |
| 448 | "Late PIO Error" : |
| 449 | ((error_bits & SYSIO_SBAFSR_PTO) ? |
| 450 | "Time Out" : |
| 451 | ((error_bits & SYSIO_SBAFSR_PBERR) ? |
| 452 | "Error Ack" : "???")))), |
| 453 | (afsr & SYSIO_SBAFSR_RD) ? 1 : 0); |
| 454 | printk("SYSIO[%x]: size[%lx] MID[%lx]\n", |
David S. Miller | 046e26a | 2008-08-27 04:54:04 -0700 | [diff] [blame] | 455 | portid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | (afsr & SYSIO_SBAFSR_SIZE) >> 42UL, |
| 457 | (afsr & SYSIO_SBAFSR_MID) >> 37UL); |
David S. Miller | 046e26a | 2008-08-27 04:54:04 -0700 | [diff] [blame] | 458 | printk("SYSIO[%x]: AFAR[%016lx]\n", portid, afar); |
| 459 | printk("SYSIO[%x]: Secondary SBUS errors [", portid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | reported = 0; |
| 461 | if (afsr & SYSIO_SBAFSR_SLE) { |
| 462 | reported++; |
| 463 | printk("(Late PIO Error)"); |
| 464 | } |
| 465 | if (afsr & SYSIO_SBAFSR_STO) { |
| 466 | reported++; |
| 467 | printk("(Time Out)"); |
| 468 | } |
| 469 | if (afsr & SYSIO_SBAFSR_SBERR) { |
| 470 | reported++; |
| 471 | printk("(Error Ack)"); |
| 472 | } |
| 473 | if (!reported) |
| 474 | printk("(none)"); |
| 475 | printk("]\n"); |
| 476 | |
| 477 | /* XXX check iommu/strbuf for further error status XXX */ |
| 478 | |
| 479 | return IRQ_HANDLED; |
| 480 | } |
| 481 | |
| 482 | #define ECC_CONTROL 0x0020UL |
| 483 | #define SYSIO_ECNTRL_ECCEN 0x8000000000000000UL /* Enable ECC Checking */ |
| 484 | #define SYSIO_ECNTRL_UEEN 0x4000000000000000UL /* Enable UE Interrupts */ |
| 485 | #define SYSIO_ECNTRL_CEEN 0x2000000000000000UL /* Enable CE Interrupts */ |
| 486 | |
| 487 | #define SYSIO_UE_INO 0x34 |
| 488 | #define SYSIO_CE_INO 0x35 |
| 489 | #define SYSIO_SBUSERR_INO 0x36 |
| 490 | |
Grant Likely | cd4cd73 | 2010-07-22 16:04:30 -0600 | [diff] [blame] | 491 | static void __init sysio_register_error_handlers(struct platform_device *op) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | { |
David S. Miller | 046e26a | 2008-08-27 04:54:04 -0700 | [diff] [blame] | 493 | struct iommu *iommu = op->dev.archdata.iommu; |
David S. Miller | 3e4d265 | 2007-04-25 15:58:22 -0700 | [diff] [blame] | 494 | unsigned long reg_base = iommu->write_complete_reg - 0x2000UL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | unsigned int irq; |
| 496 | u64 control; |
David S. Miller | 046e26a | 2008-08-27 04:54:04 -0700 | [diff] [blame] | 497 | int portid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 499 | portid = of_getintprop_default(op->dev.of_node, "portid", -1); |
David S. Miller | 046e26a | 2008-08-27 04:54:04 -0700 | [diff] [blame] | 500 | |
| 501 | irq = sbus_build_irq(op, SYSIO_UE_INO); |
David S. Miller | 96a496f | 2007-05-07 23:08:39 -0700 | [diff] [blame] | 502 | if (request_irq(irq, sysio_ue_handler, 0, |
David S. Miller | 046e26a | 2008-08-27 04:54:04 -0700 | [diff] [blame] | 503 | "SYSIO_UE", op) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | prom_printf("SYSIO[%x]: Cannot register UE interrupt.\n", |
David S. Miller | 046e26a | 2008-08-27 04:54:04 -0700 | [diff] [blame] | 505 | portid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | prom_halt(); |
| 507 | } |
| 508 | |
David S. Miller | 046e26a | 2008-08-27 04:54:04 -0700 | [diff] [blame] | 509 | irq = sbus_build_irq(op, SYSIO_CE_INO); |
David S. Miller | 96a496f | 2007-05-07 23:08:39 -0700 | [diff] [blame] | 510 | if (request_irq(irq, sysio_ce_handler, 0, |
David S. Miller | 046e26a | 2008-08-27 04:54:04 -0700 | [diff] [blame] | 511 | "SYSIO_CE", op) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | prom_printf("SYSIO[%x]: Cannot register CE interrupt.\n", |
David S. Miller | 046e26a | 2008-08-27 04:54:04 -0700 | [diff] [blame] | 513 | portid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | prom_halt(); |
| 515 | } |
| 516 | |
David S. Miller | 046e26a | 2008-08-27 04:54:04 -0700 | [diff] [blame] | 517 | irq = sbus_build_irq(op, SYSIO_SBUSERR_INO); |
David S. Miller | 96a496f | 2007-05-07 23:08:39 -0700 | [diff] [blame] | 518 | if (request_irq(irq, sysio_sbus_error_handler, 0, |
David S. Miller | 046e26a | 2008-08-27 04:54:04 -0700 | [diff] [blame] | 519 | "SYSIO_SBERR", op) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | prom_printf("SYSIO[%x]: Cannot register SBUS Error interrupt.\n", |
David S. Miller | 046e26a | 2008-08-27 04:54:04 -0700 | [diff] [blame] | 521 | portid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | prom_halt(); |
| 523 | } |
| 524 | |
| 525 | /* Now turn the error interrupts on and also enable ECC checking. */ |
| 526 | upa_writeq((SYSIO_ECNTRL_ECCEN | |
| 527 | SYSIO_ECNTRL_UEEN | |
| 528 | SYSIO_ECNTRL_CEEN), |
| 529 | reg_base + ECC_CONTROL); |
| 530 | |
David S. Miller | 3e4d265 | 2007-04-25 15:58:22 -0700 | [diff] [blame] | 531 | control = upa_readq(iommu->write_complete_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | control |= 0x100UL; /* SBUS Error Interrupt Enable */ |
David S. Miller | 3e4d265 | 2007-04-25 15:58:22 -0700 | [diff] [blame] | 533 | upa_writeq(control, iommu->write_complete_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | /* Boot time initialization. */ |
Grant Likely | cd4cd73 | 2010-07-22 16:04:30 -0600 | [diff] [blame] | 537 | static void __init sbus_iommu_init(struct platform_device *op) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | { |
Stephen Rothwell | 6a23acf | 2007-04-23 15:53:27 -0700 | [diff] [blame] | 539 | const struct linux_prom64_registers *pr; |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 540 | struct device_node *dp = op->dev.of_node; |
David S. Miller | 3e4d265 | 2007-04-25 15:58:22 -0700 | [diff] [blame] | 541 | struct iommu *iommu; |
| 542 | struct strbuf *strbuf; |
| 543 | unsigned long regs, reg_base; |
David S. Miller | 046e26a | 2008-08-27 04:54:04 -0700 | [diff] [blame] | 544 | int i, portid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | u64 control; |
David S. Miller | 25c7581 | 2006-06-22 20:21:22 -0700 | [diff] [blame] | 546 | |
| 547 | pr = of_get_property(dp, "reg", NULL); |
| 548 | if (!pr) { |
David S. Miller | ad7ad57 | 2007-07-27 22:39:14 -0700 | [diff] [blame] | 549 | prom_printf("sbus_iommu_init: Cannot map SYSIO " |
| 550 | "control registers.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | prom_halt(); |
| 552 | } |
David S. Miller | 25c7581 | 2006-06-22 20:21:22 -0700 | [diff] [blame] | 553 | regs = pr->phys_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | |
David S. Miller | ad7ad57 | 2007-07-27 22:39:14 -0700 | [diff] [blame] | 555 | iommu = kzalloc(sizeof(*iommu), GFP_ATOMIC); |
| 556 | if (!iommu) |
| 557 | goto fatal_memory_error; |
| 558 | strbuf = kzalloc(sizeof(*strbuf), GFP_ATOMIC); |
| 559 | if (!strbuf) |
| 560 | goto fatal_memory_error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | |
David S. Miller | 046e26a | 2008-08-27 04:54:04 -0700 | [diff] [blame] | 562 | op->dev.archdata.iommu = iommu; |
| 563 | op->dev.archdata.stc = strbuf; |
| 564 | op->dev.archdata.numa_node = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | |
David S. Miller | 3e4d265 | 2007-04-25 15:58:22 -0700 | [diff] [blame] | 566 | reg_base = regs + SYSIO_IOMMUREG_BASE; |
| 567 | iommu->iommu_control = reg_base + IOMMU_CONTROL; |
| 568 | iommu->iommu_tsbbase = reg_base + IOMMU_TSBBASE; |
| 569 | iommu->iommu_flush = reg_base + IOMMU_FLUSH; |
David S. Miller | ad7ad57 | 2007-07-27 22:39:14 -0700 | [diff] [blame] | 570 | iommu->iommu_tags = iommu->iommu_control + |
| 571 | (IOMMU_TAGDIAG - IOMMU_CONTROL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | |
David S. Miller | 3e4d265 | 2007-04-25 15:58:22 -0700 | [diff] [blame] | 573 | reg_base = regs + SYSIO_STRBUFREG_BASE; |
| 574 | strbuf->strbuf_control = reg_base + STRBUF_CONTROL; |
| 575 | strbuf->strbuf_pflush = reg_base + STRBUF_PFLUSH; |
| 576 | strbuf->strbuf_fsync = reg_base + STRBUF_FSYNC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | |
David S. Miller | 3e4d265 | 2007-04-25 15:58:22 -0700 | [diff] [blame] | 578 | strbuf->strbuf_enabled = 1; |
| 579 | |
| 580 | strbuf->strbuf_flushflag = (volatile unsigned long *) |
| 581 | ((((unsigned long)&strbuf->__flushflag_buf[0]) |
| 582 | + 63UL) |
| 583 | & ~63UL); |
| 584 | strbuf->strbuf_flushflag_pa = (unsigned long) |
| 585 | __pa(strbuf->strbuf_flushflag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | |
| 587 | /* The SYSIO SBUS control register is used for dummy reads |
| 588 | * in order to ensure write completion. |
| 589 | */ |
David S. Miller | 3e4d265 | 2007-04-25 15:58:22 -0700 | [diff] [blame] | 590 | iommu->write_complete_reg = regs + 0x2000UL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 592 | portid = of_getintprop_default(op->dev.of_node, "portid", -1); |
David S. Miller | 046e26a | 2008-08-27 04:54:04 -0700 | [diff] [blame] | 593 | printk(KERN_INFO "SYSIO: UPA portID %x, at %016lx\n", |
| 594 | portid, regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | |
| 596 | /* Setup for TSB_SIZE=7, TBW_SIZE=0, MMU_DE=1, MMU_EN=1 */ |
David S. Miller | c1b1a5f1 | 2008-03-19 04:52:48 -0700 | [diff] [blame] | 597 | if (iommu_table_init(iommu, IO_TSB_SIZE, MAP_BASE, 0xffffffff, -1)) |
David S. Miller | ad7ad57 | 2007-07-27 22:39:14 -0700 | [diff] [blame] | 598 | goto fatal_memory_error; |
David S. Miller | 2f3a2ef | 2007-04-11 21:38:45 -0700 | [diff] [blame] | 599 | |
David S. Miller | 3e4d265 | 2007-04-25 15:58:22 -0700 | [diff] [blame] | 600 | control = upa_readq(iommu->iommu_control); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | control = ((7UL << 16UL) | |
| 602 | (0UL << 2UL) | |
| 603 | (1UL << 1UL) | |
| 604 | (1UL << 0UL)); |
David S. Miller | 3e4d265 | 2007-04-25 15:58:22 -0700 | [diff] [blame] | 605 | upa_writeq(control, iommu->iommu_control); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | |
| 607 | /* Clean out any cruft in the IOMMU using |
| 608 | * diagnostic accesses. |
| 609 | */ |
| 610 | for (i = 0; i < 16; i++) { |
David S. Miller | 3e4d265 | 2007-04-25 15:58:22 -0700 | [diff] [blame] | 611 | unsigned long dram, tag; |
| 612 | |
| 613 | dram = iommu->iommu_control + (IOMMU_DRAMDIAG - IOMMU_CONTROL); |
| 614 | tag = iommu->iommu_control + (IOMMU_TAGDIAG - IOMMU_CONTROL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | |
| 616 | dram += (unsigned long)i * 8UL; |
| 617 | tag += (unsigned long)i * 8UL; |
| 618 | upa_writeq(0, dram); |
| 619 | upa_writeq(0, tag); |
| 620 | } |
David S. Miller | 3e4d265 | 2007-04-25 15:58:22 -0700 | [diff] [blame] | 621 | upa_readq(iommu->write_complete_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | |
| 623 | /* Give the TSB to SYSIO. */ |
David S. Miller | 3e4d265 | 2007-04-25 15:58:22 -0700 | [diff] [blame] | 624 | upa_writeq(__pa(iommu->page_table), iommu->iommu_tsbbase); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | |
| 626 | /* Setup streaming buffer, DE=1 SB_EN=1 */ |
| 627 | control = (1UL << 1UL) | (1UL << 0UL); |
David S. Miller | 3e4d265 | 2007-04-25 15:58:22 -0700 | [diff] [blame] | 628 | upa_writeq(control, strbuf->strbuf_control); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | |
| 630 | /* Clear out the tags using diagnostics. */ |
| 631 | for (i = 0; i < 16; i++) { |
| 632 | unsigned long ptag, ltag; |
| 633 | |
David S. Miller | 3e4d265 | 2007-04-25 15:58:22 -0700 | [diff] [blame] | 634 | ptag = strbuf->strbuf_control + |
| 635 | (STRBUF_PTAGDIAG - STRBUF_CONTROL); |
| 636 | ltag = strbuf->strbuf_control + |
| 637 | (STRBUF_LTAGDIAG - STRBUF_CONTROL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | ptag += (unsigned long)i * 8UL; |
| 639 | ltag += (unsigned long)i * 8UL; |
| 640 | |
| 641 | upa_writeq(0UL, ptag); |
| 642 | upa_writeq(0UL, ltag); |
| 643 | } |
| 644 | |
| 645 | /* Enable DVMA arbitration for all devices/slots. */ |
David S. Miller | 3e4d265 | 2007-04-25 15:58:22 -0700 | [diff] [blame] | 646 | control = upa_readq(iommu->write_complete_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | control |= 0x3fUL; |
David S. Miller | 3e4d265 | 2007-04-25 15:58:22 -0700 | [diff] [blame] | 648 | upa_writeq(control, iommu->write_complete_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | |
| 650 | /* Now some Xfire specific grot... */ |
| 651 | if (this_is_starfire) |
David S. Miller | 046e26a | 2008-08-27 04:54:04 -0700 | [diff] [blame] | 652 | starfire_hookup(portid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | |
David S. Miller | 046e26a | 2008-08-27 04:54:04 -0700 | [diff] [blame] | 654 | sysio_register_error_handlers(op); |
David S. Miller | ad7ad57 | 2007-07-27 22:39:14 -0700 | [diff] [blame] | 655 | return; |
| 656 | |
| 657 | fatal_memory_error: |
| 658 | prom_printf("sbus_iommu_init: Fatal memory allocation error.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | } |
David S. Miller | 8fae097 | 2006-06-20 15:23:28 -0700 | [diff] [blame] | 660 | |
David S. Miller | 046e26a | 2008-08-27 04:54:04 -0700 | [diff] [blame] | 661 | static int __init sbus_init(void) |
David S. Miller | 576c352 | 2006-06-23 15:55:45 -0700 | [diff] [blame] | 662 | { |
David S. Miller | 046e26a | 2008-08-27 04:54:04 -0700 | [diff] [blame] | 663 | struct device_node *dp; |
| 664 | |
| 665 | for_each_node_by_name(dp, "sbus") { |
Grant Likely | cd4cd73 | 2010-07-22 16:04:30 -0600 | [diff] [blame] | 666 | struct platform_device *op = of_find_device_by_node(dp); |
David S. Miller | 046e26a | 2008-08-27 04:54:04 -0700 | [diff] [blame] | 667 | |
| 668 | sbus_iommu_init(op); |
| 669 | of_propagate_archdata(op); |
| 670 | } |
David S. Miller | 576c352 | 2006-06-23 15:55:45 -0700 | [diff] [blame] | 671 | |
David S. Miller | 046e26a | 2008-08-27 04:54:04 -0700 | [diff] [blame] | 672 | return 0; |
David S. Miller | 576c352 | 2006-06-23 15:55:45 -0700 | [diff] [blame] | 673 | } |
David S. Miller | 046e26a | 2008-08-27 04:54:04 -0700 | [diff] [blame] | 674 | |
| 675 | subsys_initcall(sbus_init); |