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