David S. Miller | 9fd8b64 | 2007-03-08 21:55:49 -0800 | [diff] [blame] | 1 | /* pci_psycho.c: PSYCHO/U2P specific PCI controller support. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * |
David S. Miller | 9fd8b64 | 2007-03-08 21:55:49 -0800 | [diff] [blame] | 3 | * Copyright (C) 1997, 1998, 1999, 2007 David S. Miller (davem@davemloft.net) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * Copyright (C) 1998, 1999 Eddie C. Dost (ecd@skynet.be) |
| 5 | * Copyright (C) 1999 Jakub Jelinek (jakub@redhat.com) |
| 6 | */ |
| 7 | |
| 8 | #include <linux/kernel.h> |
| 9 | #include <linux/types.h> |
| 10 | #include <linux/pci.h> |
| 11 | #include <linux/init.h> |
| 12 | #include <linux/slab.h> |
| 13 | #include <linux/interrupt.h> |
Stephen Rothwell | 764f257 | 2008-08-07 15:33:36 -0700 | [diff] [blame] | 14 | #include <linux/of_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <asm/iommu.h> |
| 17 | #include <asm/irq.h> |
| 18 | #include <asm/starfire.h> |
David S. Miller | e87dc35 | 2006-06-21 18:18:47 -0700 | [diff] [blame] | 19 | #include <asm/prom.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
| 21 | #include "pci_impl.h" |
| 22 | #include "iommu_common.h" |
David S. Miller | a21cff3 | 2008-09-10 03:07:03 -0700 | [diff] [blame^] | 23 | #include "psycho_common.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
David S. Miller | b20bfe4 | 2008-08-30 03:13:20 -0700 | [diff] [blame] | 25 | #define DRIVER_NAME "psycho" |
| 26 | #define PFX DRIVER_NAME ": " |
| 27 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | /* All PSYCHO registers are 64-bits. The following accessor |
| 29 | * routines are how they are accessed. The REG parameter |
| 30 | * is a physical address. |
| 31 | */ |
| 32 | #define psycho_read(__reg) \ |
| 33 | ({ u64 __ret; \ |
| 34 | __asm__ __volatile__("ldxa [%1] %2, %0" \ |
| 35 | : "=r" (__ret) \ |
| 36 | : "r" (__reg), "i" (ASI_PHYS_BYPASS_EC_E) \ |
| 37 | : "memory"); \ |
| 38 | __ret; \ |
| 39 | }) |
| 40 | #define psycho_write(__reg, __val) \ |
| 41 | __asm__ __volatile__("stxa %0, [%1] %2" \ |
| 42 | : /* no outputs */ \ |
| 43 | : "r" (__val), "r" (__reg), \ |
| 44 | "i" (ASI_PHYS_BYPASS_EC_E) \ |
| 45 | : "memory") |
| 46 | |
| 47 | /* Misc. PSYCHO PCI controller register offsets and definitions. */ |
| 48 | #define PSYCHO_CONTROL 0x0010UL |
| 49 | #define PSYCHO_CONTROL_IMPL 0xf000000000000000UL /* Implementation of this PSYCHO*/ |
| 50 | #define PSYCHO_CONTROL_VER 0x0f00000000000000UL /* Version of this PSYCHO */ |
| 51 | #define PSYCHO_CONTROL_MID 0x00f8000000000000UL /* UPA Module ID of PSYCHO */ |
| 52 | #define PSYCHO_CONTROL_IGN 0x0007c00000000000UL /* Interrupt Group Number */ |
| 53 | #define PSYCHO_CONTROL_RESV 0x00003ffffffffff0UL /* Reserved */ |
| 54 | #define PSYCHO_CONTROL_APCKEN 0x0000000000000008UL /* Address Parity Check Enable */ |
| 55 | #define PSYCHO_CONTROL_APERR 0x0000000000000004UL /* Incoming System Addr Parerr */ |
| 56 | #define PSYCHO_CONTROL_IAP 0x0000000000000002UL /* Invert UPA Parity */ |
| 57 | #define PSYCHO_CONTROL_MODE 0x0000000000000001UL /* PSYCHO clock mode */ |
| 58 | #define PSYCHO_PCIA_CTRL 0x2000UL |
| 59 | #define PSYCHO_PCIB_CTRL 0x4000UL |
| 60 | #define PSYCHO_PCICTRL_RESV1 0xfffffff000000000UL /* Reserved */ |
| 61 | #define PSYCHO_PCICTRL_SBH_ERR 0x0000000800000000UL /* Streaming byte hole error */ |
| 62 | #define PSYCHO_PCICTRL_SERR 0x0000000400000000UL /* SERR signal asserted */ |
| 63 | #define PSYCHO_PCICTRL_SPEED 0x0000000200000000UL /* PCI speed (1 is U2P clock) */ |
| 64 | #define PSYCHO_PCICTRL_RESV2 0x00000001ffc00000UL /* Reserved */ |
| 65 | #define PSYCHO_PCICTRL_ARB_PARK 0x0000000000200000UL /* PCI arbitration parking */ |
| 66 | #define PSYCHO_PCICTRL_RESV3 0x00000000001ff800UL /* Reserved */ |
| 67 | #define PSYCHO_PCICTRL_SBH_INT 0x0000000000000400UL /* Streaming byte hole int enab */ |
| 68 | #define PSYCHO_PCICTRL_WEN 0x0000000000000200UL /* Power Mgmt Wake Enable */ |
| 69 | #define PSYCHO_PCICTRL_EEN 0x0000000000000100UL /* PCI Error Interrupt Enable */ |
| 70 | #define PSYCHO_PCICTRL_RESV4 0x00000000000000c0UL /* Reserved */ |
| 71 | #define PSYCHO_PCICTRL_AEN 0x000000000000003fUL /* PCI DVMA Arbitration Enable */ |
| 72 | |
| 73 | /* U2P Programmer's Manual, page 13-55, configuration space |
| 74 | * address format: |
| 75 | * |
| 76 | * 32 24 23 16 15 11 10 8 7 2 1 0 |
| 77 | * --------------------------------------------------------- |
| 78 | * |0 0 0 0 0 0 0 0 1| bus | device | function | reg | 0 0 | |
| 79 | * --------------------------------------------------------- |
| 80 | */ |
| 81 | #define PSYCHO_CONFIG_BASE(PBM) \ |
| 82 | ((PBM)->config_space | (1UL << 24)) |
| 83 | #define PSYCHO_CONFIG_ENCODE(BUS, DEVFN, REG) \ |
| 84 | (((unsigned long)(BUS) << 16) | \ |
| 85 | ((unsigned long)(DEVFN) << 8) | \ |
| 86 | ((unsigned long)(REG))) |
| 87 | |
| 88 | static void *psycho_pci_config_mkaddr(struct pci_pbm_info *pbm, |
| 89 | unsigned char bus, |
| 90 | unsigned int devfn, |
| 91 | int where) |
| 92 | { |
| 93 | if (!pbm) |
| 94 | return NULL; |
| 95 | return (void *) |
| 96 | (PSYCHO_CONFIG_BASE(pbm) | |
| 97 | PSYCHO_CONFIG_ENCODE(bus, devfn, where)); |
| 98 | } |
| 99 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | /* PSYCHO error handling support. */ |
| 101 | enum psycho_error_type { |
| 102 | UE_ERR, CE_ERR, PCI_ERR |
| 103 | }; |
| 104 | |
| 105 | /* Helper function of IOMMU error checking, which checks out |
| 106 | * the state of the streaming buffers. The IOMMU lock is |
| 107 | * held when this is called. |
| 108 | * |
| 109 | * For the PCI error case we know which PBM (and thus which |
| 110 | * streaming buffer) caused the error, but for the uncorrectable |
| 111 | * error case we do not. So we always check both streaming caches. |
| 112 | */ |
| 113 | #define PSYCHO_STRBUF_CONTROL_A 0x2800UL |
| 114 | #define PSYCHO_STRBUF_CONTROL_B 0x4800UL |
| 115 | #define PSYCHO_STRBUF_CTRL_LPTR 0x00000000000000f0UL /* LRU Lock Pointer */ |
| 116 | #define PSYCHO_STRBUF_CTRL_LENAB 0x0000000000000008UL /* LRU Lock Enable */ |
| 117 | #define PSYCHO_STRBUF_CTRL_RRDIS 0x0000000000000004UL /* Rerun Disable */ |
| 118 | #define PSYCHO_STRBUF_CTRL_DENAB 0x0000000000000002UL /* Diagnostic Mode Enable */ |
| 119 | #define PSYCHO_STRBUF_CTRL_ENAB 0x0000000000000001UL /* Streaming Buffer Enable */ |
| 120 | #define PSYCHO_STRBUF_FLUSH_A 0x2808UL |
| 121 | #define PSYCHO_STRBUF_FLUSH_B 0x4808UL |
| 122 | #define PSYCHO_STRBUF_FSYNC_A 0x2810UL |
| 123 | #define PSYCHO_STRBUF_FSYNC_B 0x4810UL |
| 124 | #define PSYCHO_STC_DATA_A 0xb000UL |
| 125 | #define PSYCHO_STC_DATA_B 0xc000UL |
| 126 | #define PSYCHO_STC_ERR_A 0xb400UL |
| 127 | #define PSYCHO_STC_ERR_B 0xc400UL |
| 128 | #define PSYCHO_STCERR_WRITE 0x0000000000000002UL /* Write Error */ |
| 129 | #define PSYCHO_STCERR_READ 0x0000000000000001UL /* Read Error */ |
| 130 | #define PSYCHO_STC_TAG_A 0xb800UL |
| 131 | #define PSYCHO_STC_TAG_B 0xc800UL |
| 132 | #define PSYCHO_STCTAG_PPN 0x0fffffff00000000UL /* Physical Page Number */ |
| 133 | #define PSYCHO_STCTAG_VPN 0x00000000ffffe000UL /* Virtual Page Number */ |
| 134 | #define PSYCHO_STCTAG_VALID 0x0000000000000002UL /* Valid */ |
| 135 | #define PSYCHO_STCTAG_WRITE 0x0000000000000001UL /* Writable */ |
| 136 | #define PSYCHO_STC_LINE_A 0xb900UL |
| 137 | #define PSYCHO_STC_LINE_B 0xc900UL |
| 138 | #define PSYCHO_STCLINE_LINDX 0x0000000001e00000UL /* LRU Index */ |
| 139 | #define PSYCHO_STCLINE_SPTR 0x00000000001f8000UL /* Dirty Data Start Pointer */ |
| 140 | #define PSYCHO_STCLINE_LADDR 0x0000000000007f00UL /* Line Address */ |
| 141 | #define PSYCHO_STCLINE_EPTR 0x00000000000000fcUL /* Dirty Data End Pointer */ |
| 142 | #define PSYCHO_STCLINE_VALID 0x0000000000000002UL /* Valid */ |
| 143 | #define PSYCHO_STCLINE_FOFN 0x0000000000000001UL /* Fetch Outstanding / Flush Necessary */ |
| 144 | |
| 145 | static DEFINE_SPINLOCK(stc_buf_lock); |
| 146 | static unsigned long stc_error_buf[128]; |
| 147 | static unsigned long stc_tag_buf[16]; |
| 148 | static unsigned long stc_line_buf[16]; |
| 149 | |
David S. Miller | d3ae4b5 | 2008-09-09 23:54:02 -0700 | [diff] [blame] | 150 | static void psycho_check_stc_error(struct pci_pbm_info *pbm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | { |
David S. Miller | 16ce82d | 2007-04-26 21:08:21 -0700 | [diff] [blame] | 152 | struct strbuf *strbuf = &pbm->stc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | unsigned long err_base, tag_base, line_base; |
| 154 | u64 control; |
| 155 | int i; |
| 156 | |
David S. Miller | d3ae4b5 | 2008-09-09 23:54:02 -0700 | [diff] [blame] | 157 | err_base = strbuf->strbuf_err_stat; |
| 158 | tag_base = strbuf->strbuf_tag_diag; |
| 159 | line_base = strbuf->strbuf_line_diag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | |
| 161 | spin_lock(&stc_buf_lock); |
| 162 | |
| 163 | /* This is __REALLY__ dangerous. When we put the |
| 164 | * streaming buffer into diagnostic mode to probe |
| 165 | * it's tags and error status, we _must_ clear all |
| 166 | * of the line tag valid bits before re-enabling |
| 167 | * the streaming buffer. If any dirty data lives |
| 168 | * in the STC when we do this, we will end up |
| 169 | * invalidating it before it has a chance to reach |
| 170 | * main memory. |
| 171 | */ |
| 172 | control = psycho_read(strbuf->strbuf_control); |
| 173 | psycho_write(strbuf->strbuf_control, |
| 174 | (control | PSYCHO_STRBUF_CTRL_DENAB)); |
| 175 | for (i = 0; i < 128; i++) { |
| 176 | unsigned long val; |
| 177 | |
| 178 | val = psycho_read(err_base + (i * 8UL)); |
| 179 | psycho_write(err_base + (i * 8UL), 0UL); |
| 180 | stc_error_buf[i] = val; |
| 181 | } |
| 182 | for (i = 0; i < 16; i++) { |
| 183 | stc_tag_buf[i] = psycho_read(tag_base + (i * 8UL)); |
| 184 | stc_line_buf[i] = psycho_read(line_base + (i * 8UL)); |
| 185 | psycho_write(tag_base + (i * 8UL), 0UL); |
| 186 | psycho_write(line_base + (i * 8UL), 0UL); |
| 187 | } |
| 188 | |
| 189 | /* OK, state is logged, exit diagnostic mode. */ |
| 190 | psycho_write(strbuf->strbuf_control, control); |
| 191 | |
| 192 | for (i = 0; i < 16; i++) { |
| 193 | int j, saw_error, first, last; |
| 194 | |
| 195 | saw_error = 0; |
| 196 | first = i * 8; |
| 197 | last = first + 8; |
| 198 | for (j = first; j < last; j++) { |
| 199 | unsigned long errval = stc_error_buf[j]; |
| 200 | if (errval != 0) { |
| 201 | saw_error++; |
David S. Miller | 6c108f1 | 2007-05-07 23:49:01 -0700 | [diff] [blame] | 202 | printk("%s: STC_ERR(%d)[wr(%d)rd(%d)]\n", |
| 203 | pbm->name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | j, |
| 205 | (errval & PSYCHO_STCERR_WRITE) ? 1 : 0, |
| 206 | (errval & PSYCHO_STCERR_READ) ? 1 : 0); |
| 207 | } |
| 208 | } |
| 209 | if (saw_error != 0) { |
| 210 | unsigned long tagval = stc_tag_buf[i]; |
| 211 | unsigned long lineval = stc_line_buf[i]; |
David S. Miller | 6c108f1 | 2007-05-07 23:49:01 -0700 | [diff] [blame] | 212 | printk("%s: STC_TAG(%d)[PA(%016lx)VA(%08lx)V(%d)W(%d)]\n", |
| 213 | pbm->name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | i, |
| 215 | ((tagval & PSYCHO_STCTAG_PPN) >> 19UL), |
| 216 | (tagval & PSYCHO_STCTAG_VPN), |
| 217 | ((tagval & PSYCHO_STCTAG_VALID) ? 1 : 0), |
| 218 | ((tagval & PSYCHO_STCTAG_WRITE) ? 1 : 0)); |
David S. Miller | 6c108f1 | 2007-05-07 23:49:01 -0700 | [diff] [blame] | 219 | printk("%s: STC_LINE(%d)[LIDX(%lx)SP(%lx)LADDR(%lx)EP(%lx)" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | "V(%d)FOFN(%d)]\n", |
David S. Miller | 6c108f1 | 2007-05-07 23:49:01 -0700 | [diff] [blame] | 221 | pbm->name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | i, |
| 223 | ((lineval & PSYCHO_STCLINE_LINDX) >> 21UL), |
| 224 | ((lineval & PSYCHO_STCLINE_SPTR) >> 15UL), |
| 225 | ((lineval & PSYCHO_STCLINE_LADDR) >> 8UL), |
| 226 | ((lineval & PSYCHO_STCLINE_EPTR) >> 2UL), |
| 227 | ((lineval & PSYCHO_STCLINE_VALID) ? 1 : 0), |
| 228 | ((lineval & PSYCHO_STCLINE_FOFN) ? 1 : 0)); |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | spin_unlock(&stc_buf_lock); |
| 233 | } |
| 234 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | /* When an Uncorrectable Error or a PCI Error happens, we |
| 236 | * interrogate the IOMMU state to see if it is the cause. |
| 237 | */ |
| 238 | #define PSYCHO_IOMMU_CONTROL 0x0200UL |
| 239 | #define PSYCHO_IOMMU_CTRL_RESV 0xfffffffff9000000UL /* Reserved */ |
| 240 | #define PSYCHO_IOMMU_CTRL_XLTESTAT 0x0000000006000000UL /* Translation Error Status */ |
| 241 | #define PSYCHO_IOMMU_CTRL_XLTEERR 0x0000000001000000UL /* Translation Error encountered */ |
| 242 | #define PSYCHO_IOMMU_CTRL_LCKEN 0x0000000000800000UL /* Enable translation locking */ |
| 243 | #define PSYCHO_IOMMU_CTRL_LCKPTR 0x0000000000780000UL /* Translation lock pointer */ |
| 244 | #define PSYCHO_IOMMU_CTRL_TSBSZ 0x0000000000070000UL /* TSB Size */ |
| 245 | #define PSYCHO_IOMMU_TSBSZ_1K 0x0000000000000000UL /* TSB Table 1024 8-byte entries */ |
| 246 | #define PSYCHO_IOMMU_TSBSZ_2K 0x0000000000010000UL /* TSB Table 2048 8-byte entries */ |
| 247 | #define PSYCHO_IOMMU_TSBSZ_4K 0x0000000000020000UL /* TSB Table 4096 8-byte entries */ |
| 248 | #define PSYCHO_IOMMU_TSBSZ_8K 0x0000000000030000UL /* TSB Table 8192 8-byte entries */ |
| 249 | #define PSYCHO_IOMMU_TSBSZ_16K 0x0000000000040000UL /* TSB Table 16k 8-byte entries */ |
| 250 | #define PSYCHO_IOMMU_TSBSZ_32K 0x0000000000050000UL /* TSB Table 32k 8-byte entries */ |
| 251 | #define PSYCHO_IOMMU_TSBSZ_64K 0x0000000000060000UL /* TSB Table 64k 8-byte entries */ |
| 252 | #define PSYCHO_IOMMU_TSBSZ_128K 0x0000000000070000UL /* TSB Table 128k 8-byte entries */ |
| 253 | #define PSYCHO_IOMMU_CTRL_RESV2 0x000000000000fff8UL /* Reserved */ |
| 254 | #define PSYCHO_IOMMU_CTRL_TBWSZ 0x0000000000000004UL /* Assumed page size, 0=8k 1=64k */ |
| 255 | #define PSYCHO_IOMMU_CTRL_DENAB 0x0000000000000002UL /* Diagnostic mode enable */ |
| 256 | #define PSYCHO_IOMMU_CTRL_ENAB 0x0000000000000001UL /* IOMMU Enable */ |
| 257 | #define PSYCHO_IOMMU_TSBBASE 0x0208UL |
| 258 | #define PSYCHO_IOMMU_FLUSH 0x0210UL |
| 259 | #define PSYCHO_IOMMU_TAG 0xa580UL |
| 260 | #define PSYCHO_IOMMU_TAG_ERRSTS (0x3UL << 23UL) |
| 261 | #define PSYCHO_IOMMU_TAG_ERR (0x1UL << 22UL) |
| 262 | #define PSYCHO_IOMMU_TAG_WRITE (0x1UL << 21UL) |
| 263 | #define PSYCHO_IOMMU_TAG_STREAM (0x1UL << 20UL) |
| 264 | #define PSYCHO_IOMMU_TAG_SIZE (0x1UL << 19UL) |
| 265 | #define PSYCHO_IOMMU_TAG_VPAGE 0x7ffffUL |
| 266 | #define PSYCHO_IOMMU_DATA 0xa600UL |
| 267 | #define PSYCHO_IOMMU_DATA_VALID (1UL << 30UL) |
| 268 | #define PSYCHO_IOMMU_DATA_CACHE (1UL << 28UL) |
| 269 | #define PSYCHO_IOMMU_DATA_PPAGE 0xfffffffUL |
David S. Miller | 34768bc | 2007-05-07 23:06:27 -0700 | [diff] [blame] | 270 | static void psycho_check_iommu_error(struct pci_pbm_info *pbm, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | unsigned long afsr, |
| 272 | unsigned long afar, |
| 273 | enum psycho_error_type type) |
| 274 | { |
David S. Miller | 34768bc | 2007-05-07 23:06:27 -0700 | [diff] [blame] | 275 | struct iommu *iommu = pbm->iommu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | unsigned long iommu_tag[16]; |
| 277 | unsigned long iommu_data[16]; |
| 278 | unsigned long flags; |
| 279 | u64 control; |
| 280 | int i; |
| 281 | |
| 282 | spin_lock_irqsave(&iommu->lock, flags); |
| 283 | control = psycho_read(iommu->iommu_control); |
| 284 | if (control & PSYCHO_IOMMU_CTRL_XLTEERR) { |
| 285 | char *type_string; |
| 286 | |
| 287 | /* Clear the error encountered bit. */ |
| 288 | control &= ~PSYCHO_IOMMU_CTRL_XLTEERR; |
| 289 | psycho_write(iommu->iommu_control, control); |
| 290 | |
| 291 | switch((control & PSYCHO_IOMMU_CTRL_XLTESTAT) >> 25UL) { |
| 292 | case 0: |
| 293 | type_string = "Protection Error"; |
| 294 | break; |
| 295 | case 1: |
| 296 | type_string = "Invalid Error"; |
| 297 | break; |
| 298 | case 2: |
| 299 | type_string = "TimeOut Error"; |
| 300 | break; |
| 301 | case 3: |
| 302 | default: |
| 303 | type_string = "ECC Error"; |
| 304 | break; |
| 305 | }; |
David S. Miller | 6c108f1 | 2007-05-07 23:49:01 -0700 | [diff] [blame] | 306 | printk("%s: IOMMU Error, type[%s]\n", |
| 307 | pbm->name, type_string); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | |
| 309 | /* Put the IOMMU into diagnostic mode and probe |
| 310 | * it's TLB for entries with error status. |
| 311 | * |
| 312 | * It is very possible for another DVMA to occur |
| 313 | * while we do this probe, and corrupt the system |
| 314 | * further. But we are so screwed at this point |
| 315 | * that we are likely to crash hard anyways, so |
| 316 | * get as much diagnostic information to the |
| 317 | * console as we can. |
| 318 | */ |
| 319 | psycho_write(iommu->iommu_control, |
| 320 | control | PSYCHO_IOMMU_CTRL_DENAB); |
| 321 | for (i = 0; i < 16; i++) { |
David S. Miller | 34768bc | 2007-05-07 23:06:27 -0700 | [diff] [blame] | 322 | unsigned long base = pbm->controller_regs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | |
| 324 | iommu_tag[i] = |
| 325 | psycho_read(base + PSYCHO_IOMMU_TAG + (i * 8UL)); |
| 326 | iommu_data[i] = |
| 327 | psycho_read(base + PSYCHO_IOMMU_DATA + (i * 8UL)); |
| 328 | |
| 329 | /* Now clear out the entry. */ |
| 330 | psycho_write(base + PSYCHO_IOMMU_TAG + (i * 8UL), 0); |
| 331 | psycho_write(base + PSYCHO_IOMMU_DATA + (i * 8UL), 0); |
| 332 | } |
| 333 | |
| 334 | /* Leave diagnostic mode. */ |
| 335 | psycho_write(iommu->iommu_control, control); |
| 336 | |
| 337 | for (i = 0; i < 16; i++) { |
| 338 | unsigned long tag, data; |
| 339 | |
| 340 | tag = iommu_tag[i]; |
| 341 | if (!(tag & PSYCHO_IOMMU_TAG_ERR)) |
| 342 | continue; |
| 343 | |
| 344 | data = iommu_data[i]; |
| 345 | switch((tag & PSYCHO_IOMMU_TAG_ERRSTS) >> 23UL) { |
| 346 | case 0: |
| 347 | type_string = "Protection Error"; |
| 348 | break; |
| 349 | case 1: |
| 350 | type_string = "Invalid Error"; |
| 351 | break; |
| 352 | case 2: |
| 353 | type_string = "TimeOut Error"; |
| 354 | break; |
| 355 | case 3: |
| 356 | default: |
| 357 | type_string = "ECC Error"; |
| 358 | break; |
| 359 | }; |
David S. Miller | 6c108f1 | 2007-05-07 23:49:01 -0700 | [diff] [blame] | 360 | printk("%s: IOMMU TAG(%d)[error(%s) wr(%d) str(%d) sz(%dK) vpg(%08lx)]\n", |
| 361 | pbm->name, i, type_string, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | ((tag & PSYCHO_IOMMU_TAG_WRITE) ? 1 : 0), |
| 363 | ((tag & PSYCHO_IOMMU_TAG_STREAM) ? 1 : 0), |
| 364 | ((tag & PSYCHO_IOMMU_TAG_SIZE) ? 64 : 8), |
| 365 | (tag & PSYCHO_IOMMU_TAG_VPAGE) << IOMMU_PAGE_SHIFT); |
David S. Miller | 6c108f1 | 2007-05-07 23:49:01 -0700 | [diff] [blame] | 366 | printk("%s: IOMMU DATA(%d)[valid(%d) cache(%d) ppg(%016lx)]\n", |
| 367 | pbm->name, i, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | ((data & PSYCHO_IOMMU_DATA_VALID) ? 1 : 0), |
| 369 | ((data & PSYCHO_IOMMU_DATA_CACHE) ? 1 : 0), |
| 370 | (data & PSYCHO_IOMMU_DATA_PPAGE) << IOMMU_PAGE_SHIFT); |
| 371 | } |
| 372 | } |
David S. Miller | d3ae4b5 | 2008-09-09 23:54:02 -0700 | [diff] [blame] | 373 | psycho_check_stc_error(pbm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | spin_unlock_irqrestore(&iommu->lock, flags); |
| 375 | } |
| 376 | |
| 377 | /* Uncorrectable Errors. Cause of the error and the address are |
| 378 | * recorded in the UE_AFSR and UE_AFAR of PSYCHO. They are errors |
| 379 | * relating to UPA interface transactions. |
| 380 | */ |
| 381 | #define PSYCHO_UE_AFSR 0x0030UL |
| 382 | #define PSYCHO_UEAFSR_PPIO 0x8000000000000000UL /* Primary PIO is cause */ |
| 383 | #define PSYCHO_UEAFSR_PDRD 0x4000000000000000UL /* Primary DVMA read is cause */ |
| 384 | #define PSYCHO_UEAFSR_PDWR 0x2000000000000000UL /* Primary DVMA write is cause */ |
| 385 | #define PSYCHO_UEAFSR_SPIO 0x1000000000000000UL /* Secondary PIO is cause */ |
| 386 | #define PSYCHO_UEAFSR_SDRD 0x0800000000000000UL /* Secondary DVMA read is cause */ |
| 387 | #define PSYCHO_UEAFSR_SDWR 0x0400000000000000UL /* Secondary DVMA write is cause*/ |
| 388 | #define PSYCHO_UEAFSR_RESV1 0x03ff000000000000UL /* Reserved */ |
| 389 | #define PSYCHO_UEAFSR_BMSK 0x0000ffff00000000UL /* Bytemask of failed transfer */ |
| 390 | #define PSYCHO_UEAFSR_DOFF 0x00000000e0000000UL /* Doubleword Offset */ |
| 391 | #define PSYCHO_UEAFSR_MID 0x000000001f000000UL /* UPA MID causing the fault */ |
| 392 | #define PSYCHO_UEAFSR_BLK 0x0000000000800000UL /* Trans was block operation */ |
| 393 | #define PSYCHO_UEAFSR_RESV2 0x00000000007fffffUL /* Reserved */ |
| 394 | #define PSYCHO_UE_AFAR 0x0038UL |
| 395 | |
Al Viro | 6d24c8d | 2006-10-08 08:23:28 -0400 | [diff] [blame] | 396 | static irqreturn_t psycho_ue_intr(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | { |
David S. Miller | 34768bc | 2007-05-07 23:06:27 -0700 | [diff] [blame] | 398 | struct pci_pbm_info *pbm = dev_id; |
David S. Miller | 34768bc | 2007-05-07 23:06:27 -0700 | [diff] [blame] | 399 | unsigned long afsr_reg = pbm->controller_regs + PSYCHO_UE_AFSR; |
| 400 | unsigned long afar_reg = pbm->controller_regs + PSYCHO_UE_AFAR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | unsigned long afsr, afar, error_bits; |
| 402 | int reported; |
| 403 | |
| 404 | /* Latch uncorrectable error status. */ |
| 405 | afar = psycho_read(afar_reg); |
| 406 | afsr = psycho_read(afsr_reg); |
| 407 | |
| 408 | /* Clear the primary/secondary error status bits. */ |
| 409 | error_bits = afsr & |
| 410 | (PSYCHO_UEAFSR_PPIO | PSYCHO_UEAFSR_PDRD | PSYCHO_UEAFSR_PDWR | |
| 411 | PSYCHO_UEAFSR_SPIO | PSYCHO_UEAFSR_SDRD | PSYCHO_UEAFSR_SDWR); |
| 412 | if (!error_bits) |
| 413 | return IRQ_NONE; |
| 414 | psycho_write(afsr_reg, error_bits); |
| 415 | |
| 416 | /* Log the error. */ |
David S. Miller | 6c108f1 | 2007-05-07 23:49:01 -0700 | [diff] [blame] | 417 | printk("%s: Uncorrectable Error, primary error type[%s]\n", |
| 418 | pbm->name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | (((error_bits & PSYCHO_UEAFSR_PPIO) ? |
| 420 | "PIO" : |
| 421 | ((error_bits & PSYCHO_UEAFSR_PDRD) ? |
| 422 | "DMA Read" : |
| 423 | ((error_bits & PSYCHO_UEAFSR_PDWR) ? |
| 424 | "DMA Write" : "???"))))); |
David S. Miller | 6c108f1 | 2007-05-07 23:49:01 -0700 | [diff] [blame] | 425 | printk("%s: bytemask[%04lx] dword_offset[%lx] UPA_MID[%02lx] was_block(%d)\n", |
| 426 | pbm->name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | (afsr & PSYCHO_UEAFSR_BMSK) >> 32UL, |
| 428 | (afsr & PSYCHO_UEAFSR_DOFF) >> 29UL, |
| 429 | (afsr & PSYCHO_UEAFSR_MID) >> 24UL, |
| 430 | ((afsr & PSYCHO_UEAFSR_BLK) ? 1 : 0)); |
David S. Miller | 6c108f1 | 2007-05-07 23:49:01 -0700 | [diff] [blame] | 431 | printk("%s: UE AFAR [%016lx]\n", pbm->name, afar); |
| 432 | printk("%s: UE Secondary errors [", pbm->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | reported = 0; |
| 434 | if (afsr & PSYCHO_UEAFSR_SPIO) { |
| 435 | reported++; |
| 436 | printk("(PIO)"); |
| 437 | } |
| 438 | if (afsr & PSYCHO_UEAFSR_SDRD) { |
| 439 | reported++; |
| 440 | printk("(DMA Read)"); |
| 441 | } |
| 442 | if (afsr & PSYCHO_UEAFSR_SDWR) { |
| 443 | reported++; |
| 444 | printk("(DMA Write)"); |
| 445 | } |
| 446 | if (!reported) |
| 447 | printk("(none)"); |
| 448 | printk("]\n"); |
| 449 | |
David S. Miller | 34768bc | 2007-05-07 23:06:27 -0700 | [diff] [blame] | 450 | /* Interrogate both IOMMUs for error status. */ |
David S. Miller | d3ae4b5 | 2008-09-09 23:54:02 -0700 | [diff] [blame] | 451 | psycho_check_iommu_error(pbm, afsr, afar, UE_ERR); |
| 452 | if (pbm->sibling) |
| 453 | psycho_check_iommu_error(pbm->sibling, afsr, afar, UE_ERR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | |
| 455 | return IRQ_HANDLED; |
| 456 | } |
| 457 | |
| 458 | /* Correctable Errors. */ |
| 459 | #define PSYCHO_CE_AFSR 0x0040UL |
| 460 | #define PSYCHO_CEAFSR_PPIO 0x8000000000000000UL /* Primary PIO is cause */ |
| 461 | #define PSYCHO_CEAFSR_PDRD 0x4000000000000000UL /* Primary DVMA read is cause */ |
| 462 | #define PSYCHO_CEAFSR_PDWR 0x2000000000000000UL /* Primary DVMA write is cause */ |
| 463 | #define PSYCHO_CEAFSR_SPIO 0x1000000000000000UL /* Secondary PIO is cause */ |
| 464 | #define PSYCHO_CEAFSR_SDRD 0x0800000000000000UL /* Secondary DVMA read is cause */ |
| 465 | #define PSYCHO_CEAFSR_SDWR 0x0400000000000000UL /* Secondary DVMA write is cause*/ |
| 466 | #define PSYCHO_CEAFSR_RESV1 0x0300000000000000UL /* Reserved */ |
| 467 | #define PSYCHO_CEAFSR_ESYND 0x00ff000000000000UL /* Syndrome Bits */ |
| 468 | #define PSYCHO_CEAFSR_BMSK 0x0000ffff00000000UL /* Bytemask of failed transfer */ |
| 469 | #define PSYCHO_CEAFSR_DOFF 0x00000000e0000000UL /* Double Offset */ |
| 470 | #define PSYCHO_CEAFSR_MID 0x000000001f000000UL /* UPA MID causing the fault */ |
| 471 | #define PSYCHO_CEAFSR_BLK 0x0000000000800000UL /* Trans was block operation */ |
| 472 | #define PSYCHO_CEAFSR_RESV2 0x00000000007fffffUL /* Reserved */ |
| 473 | #define PSYCHO_CE_AFAR 0x0040UL |
| 474 | |
Al Viro | 6d24c8d | 2006-10-08 08:23:28 -0400 | [diff] [blame] | 475 | static irqreturn_t psycho_ce_intr(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | { |
David S. Miller | 34768bc | 2007-05-07 23:06:27 -0700 | [diff] [blame] | 477 | struct pci_pbm_info *pbm = dev_id; |
David S. Miller | 34768bc | 2007-05-07 23:06:27 -0700 | [diff] [blame] | 478 | unsigned long afsr_reg = pbm->controller_regs + PSYCHO_CE_AFSR; |
| 479 | unsigned long afar_reg = pbm->controller_regs + PSYCHO_CE_AFAR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | unsigned long afsr, afar, error_bits; |
| 481 | int reported; |
| 482 | |
| 483 | /* Latch error status. */ |
| 484 | afar = psycho_read(afar_reg); |
| 485 | afsr = psycho_read(afsr_reg); |
| 486 | |
| 487 | /* Clear primary/secondary error status bits. */ |
| 488 | error_bits = afsr & |
| 489 | (PSYCHO_CEAFSR_PPIO | PSYCHO_CEAFSR_PDRD | PSYCHO_CEAFSR_PDWR | |
| 490 | PSYCHO_CEAFSR_SPIO | PSYCHO_CEAFSR_SDRD | PSYCHO_CEAFSR_SDWR); |
| 491 | if (!error_bits) |
| 492 | return IRQ_NONE; |
| 493 | psycho_write(afsr_reg, error_bits); |
| 494 | |
| 495 | /* Log the error. */ |
David S. Miller | 6c108f1 | 2007-05-07 23:49:01 -0700 | [diff] [blame] | 496 | printk("%s: Correctable Error, primary error type[%s]\n", |
| 497 | pbm->name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | (((error_bits & PSYCHO_CEAFSR_PPIO) ? |
| 499 | "PIO" : |
| 500 | ((error_bits & PSYCHO_CEAFSR_PDRD) ? |
| 501 | "DMA Read" : |
| 502 | ((error_bits & PSYCHO_CEAFSR_PDWR) ? |
| 503 | "DMA Write" : "???"))))); |
| 504 | |
| 505 | /* XXX Use syndrome and afar to print out module string just like |
| 506 | * XXX UDB CE trap handler does... -DaveM |
| 507 | */ |
David S. Miller | 6c108f1 | 2007-05-07 23:49:01 -0700 | [diff] [blame] | 508 | printk("%s: syndrome[%02lx] bytemask[%04lx] dword_offset[%lx] " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | "UPA_MID[%02lx] was_block(%d)\n", |
David S. Miller | 6c108f1 | 2007-05-07 23:49:01 -0700 | [diff] [blame] | 510 | pbm->name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | (afsr & PSYCHO_CEAFSR_ESYND) >> 48UL, |
| 512 | (afsr & PSYCHO_CEAFSR_BMSK) >> 32UL, |
| 513 | (afsr & PSYCHO_CEAFSR_DOFF) >> 29UL, |
| 514 | (afsr & PSYCHO_CEAFSR_MID) >> 24UL, |
| 515 | ((afsr & PSYCHO_CEAFSR_BLK) ? 1 : 0)); |
David S. Miller | 6c108f1 | 2007-05-07 23:49:01 -0700 | [diff] [blame] | 516 | printk("%s: CE AFAR [%016lx]\n", pbm->name, afar); |
| 517 | printk("%s: CE Secondary errors [", pbm->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | reported = 0; |
| 519 | if (afsr & PSYCHO_CEAFSR_SPIO) { |
| 520 | reported++; |
| 521 | printk("(PIO)"); |
| 522 | } |
| 523 | if (afsr & PSYCHO_CEAFSR_SDRD) { |
| 524 | reported++; |
| 525 | printk("(DMA Read)"); |
| 526 | } |
| 527 | if (afsr & PSYCHO_CEAFSR_SDWR) { |
| 528 | reported++; |
| 529 | printk("(DMA Write)"); |
| 530 | } |
| 531 | if (!reported) |
| 532 | printk("(none)"); |
| 533 | printk("]\n"); |
| 534 | |
| 535 | return IRQ_HANDLED; |
| 536 | } |
| 537 | |
| 538 | /* PCI Errors. They are signalled by the PCI bus module since they |
| 539 | * are associated with a specific bus segment. |
| 540 | */ |
| 541 | #define PSYCHO_PCI_AFSR_A 0x2010UL |
| 542 | #define PSYCHO_PCI_AFSR_B 0x4010UL |
| 543 | #define PSYCHO_PCIAFSR_PMA 0x8000000000000000UL /* Primary Master Abort Error */ |
| 544 | #define PSYCHO_PCIAFSR_PTA 0x4000000000000000UL /* Primary Target Abort Error */ |
| 545 | #define PSYCHO_PCIAFSR_PRTRY 0x2000000000000000UL /* Primary Excessive Retries */ |
| 546 | #define PSYCHO_PCIAFSR_PPERR 0x1000000000000000UL /* Primary Parity Error */ |
| 547 | #define PSYCHO_PCIAFSR_SMA 0x0800000000000000UL /* Secondary Master Abort Error */ |
| 548 | #define PSYCHO_PCIAFSR_STA 0x0400000000000000UL /* Secondary Target Abort Error */ |
| 549 | #define PSYCHO_PCIAFSR_SRTRY 0x0200000000000000UL /* Secondary Excessive Retries */ |
| 550 | #define PSYCHO_PCIAFSR_SPERR 0x0100000000000000UL /* Secondary Parity Error */ |
| 551 | #define PSYCHO_PCIAFSR_RESV1 0x00ff000000000000UL /* Reserved */ |
| 552 | #define PSYCHO_PCIAFSR_BMSK 0x0000ffff00000000UL /* Bytemask of failed transfer */ |
| 553 | #define PSYCHO_PCIAFSR_BLK 0x0000000080000000UL /* Trans was block operation */ |
| 554 | #define PSYCHO_PCIAFSR_RESV2 0x0000000040000000UL /* Reserved */ |
| 555 | #define PSYCHO_PCIAFSR_MID 0x000000003e000000UL /* MID causing the error */ |
| 556 | #define PSYCHO_PCIAFSR_RESV3 0x0000000001ffffffUL /* Reserved */ |
| 557 | #define PSYCHO_PCI_AFAR_A 0x2018UL |
| 558 | #define PSYCHO_PCI_AFAR_B 0x4018UL |
| 559 | |
David S. Miller | d3ae4b5 | 2008-09-09 23:54:02 -0700 | [diff] [blame] | 560 | static irqreturn_t psycho_pcierr_intr_other(struct pci_pbm_info *pbm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | { |
David S. Miller | d3ae4b5 | 2008-09-09 23:54:02 -0700 | [diff] [blame] | 562 | unsigned long csr, csr_error_bits; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | irqreturn_t ret = IRQ_NONE; |
| 564 | u16 stat; |
| 565 | |
David S. Miller | d3ae4b5 | 2008-09-09 23:54:02 -0700 | [diff] [blame] | 566 | csr = psycho_read(pbm->pci_csr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | csr_error_bits = |
| 568 | csr & (PSYCHO_PCICTRL_SBH_ERR | PSYCHO_PCICTRL_SERR); |
| 569 | if (csr_error_bits) { |
| 570 | /* Clear the errors. */ |
David S. Miller | d3ae4b5 | 2008-09-09 23:54:02 -0700 | [diff] [blame] | 571 | psycho_write(pbm->pci_csr, csr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | |
| 573 | /* Log 'em. */ |
| 574 | if (csr_error_bits & PSYCHO_PCICTRL_SBH_ERR) |
| 575 | printk("%s: PCI streaming byte hole error asserted.\n", |
| 576 | pbm->name); |
| 577 | if (csr_error_bits & PSYCHO_PCICTRL_SERR) |
| 578 | printk("%s: PCI SERR signal asserted.\n", pbm->name); |
| 579 | ret = IRQ_HANDLED; |
| 580 | } |
| 581 | pci_read_config_word(pbm->pci_bus->self, PCI_STATUS, &stat); |
| 582 | if (stat & (PCI_STATUS_PARITY | |
| 583 | PCI_STATUS_SIG_TARGET_ABORT | |
| 584 | PCI_STATUS_REC_TARGET_ABORT | |
| 585 | PCI_STATUS_REC_MASTER_ABORT | |
| 586 | PCI_STATUS_SIG_SYSTEM_ERROR)) { |
| 587 | printk("%s: PCI bus error, PCI_STATUS[%04x]\n", |
| 588 | pbm->name, stat); |
| 589 | pci_write_config_word(pbm->pci_bus->self, PCI_STATUS, 0xffff); |
| 590 | ret = IRQ_HANDLED; |
| 591 | } |
| 592 | return ret; |
| 593 | } |
| 594 | |
Al Viro | 6d24c8d | 2006-10-08 08:23:28 -0400 | [diff] [blame] | 595 | static irqreturn_t psycho_pcierr_intr(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | { |
| 597 | struct pci_pbm_info *pbm = dev_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | unsigned long afsr_reg, afar_reg; |
| 599 | unsigned long afsr, afar, error_bits; |
David S. Miller | d3ae4b5 | 2008-09-09 23:54:02 -0700 | [diff] [blame] | 600 | int reported; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | |
David S. Miller | d3ae4b5 | 2008-09-09 23:54:02 -0700 | [diff] [blame] | 602 | afsr_reg = pbm->pci_afsr; |
| 603 | afar_reg = pbm->pci_afar; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | |
| 605 | /* Latch error status. */ |
| 606 | afar = psycho_read(afar_reg); |
| 607 | afsr = psycho_read(afsr_reg); |
| 608 | |
| 609 | /* Clear primary/secondary error status bits. */ |
| 610 | error_bits = afsr & |
| 611 | (PSYCHO_PCIAFSR_PMA | PSYCHO_PCIAFSR_PTA | |
| 612 | PSYCHO_PCIAFSR_PRTRY | PSYCHO_PCIAFSR_PPERR | |
| 613 | PSYCHO_PCIAFSR_SMA | PSYCHO_PCIAFSR_STA | |
| 614 | PSYCHO_PCIAFSR_SRTRY | PSYCHO_PCIAFSR_SPERR); |
| 615 | if (!error_bits) |
David S. Miller | d3ae4b5 | 2008-09-09 23:54:02 -0700 | [diff] [blame] | 616 | return psycho_pcierr_intr_other(pbm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | psycho_write(afsr_reg, error_bits); |
| 618 | |
| 619 | /* Log the error. */ |
David S. Miller | 6c108f1 | 2007-05-07 23:49:01 -0700 | [diff] [blame] | 620 | printk("%s: PCI Error, primary error type[%s]\n", |
| 621 | pbm->name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | (((error_bits & PSYCHO_PCIAFSR_PMA) ? |
| 623 | "Master Abort" : |
| 624 | ((error_bits & PSYCHO_PCIAFSR_PTA) ? |
| 625 | "Target Abort" : |
| 626 | ((error_bits & PSYCHO_PCIAFSR_PRTRY) ? |
| 627 | "Excessive Retries" : |
| 628 | ((error_bits & PSYCHO_PCIAFSR_PPERR) ? |
| 629 | "Parity Error" : "???")))))); |
David S. Miller | 6c108f1 | 2007-05-07 23:49:01 -0700 | [diff] [blame] | 630 | printk("%s: bytemask[%04lx] UPA_MID[%02lx] was_block(%d)\n", |
| 631 | pbm->name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | (afsr & PSYCHO_PCIAFSR_BMSK) >> 32UL, |
| 633 | (afsr & PSYCHO_PCIAFSR_MID) >> 25UL, |
| 634 | (afsr & PSYCHO_PCIAFSR_BLK) ? 1 : 0); |
David S. Miller | 6c108f1 | 2007-05-07 23:49:01 -0700 | [diff] [blame] | 635 | printk("%s: PCI AFAR [%016lx]\n", pbm->name, afar); |
| 636 | printk("%s: PCI Secondary errors [", pbm->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | reported = 0; |
| 638 | if (afsr & PSYCHO_PCIAFSR_SMA) { |
| 639 | reported++; |
| 640 | printk("(Master Abort)"); |
| 641 | } |
| 642 | if (afsr & PSYCHO_PCIAFSR_STA) { |
| 643 | reported++; |
| 644 | printk("(Target Abort)"); |
| 645 | } |
| 646 | if (afsr & PSYCHO_PCIAFSR_SRTRY) { |
| 647 | reported++; |
| 648 | printk("(Excessive Retries)"); |
| 649 | } |
| 650 | if (afsr & PSYCHO_PCIAFSR_SPERR) { |
| 651 | reported++; |
| 652 | printk("(Parity Error)"); |
| 653 | } |
| 654 | if (!reported) |
| 655 | printk("(none)"); |
| 656 | printk("]\n"); |
| 657 | |
| 658 | /* For the error types shown, scan PBM's PCI bus for devices |
| 659 | * which have logged that error type. |
| 660 | */ |
| 661 | |
| 662 | /* If we see a Target Abort, this could be the result of an |
| 663 | * IOMMU translation error of some sort. It is extremely |
| 664 | * useful to log this information as usually it indicates |
| 665 | * a bug in the IOMMU support code or a PCI device driver. |
| 666 | */ |
| 667 | if (error_bits & (PSYCHO_PCIAFSR_PTA | PSYCHO_PCIAFSR_STA)) { |
David S. Miller | 34768bc | 2007-05-07 23:06:27 -0700 | [diff] [blame] | 668 | psycho_check_iommu_error(pbm, afsr, afar, PCI_ERR); |
David S. Miller | 6c108f1 | 2007-05-07 23:49:01 -0700 | [diff] [blame] | 669 | pci_scan_for_target_abort(pbm, pbm->pci_bus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | } |
| 671 | if (error_bits & (PSYCHO_PCIAFSR_PMA | PSYCHO_PCIAFSR_SMA)) |
David S. Miller | 6c108f1 | 2007-05-07 23:49:01 -0700 | [diff] [blame] | 672 | pci_scan_for_master_abort(pbm, pbm->pci_bus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | |
| 674 | /* For excessive retries, PSYCHO/PBM will abort the device |
| 675 | * and there is no way to specifically check for excessive |
| 676 | * retries in the config space status registers. So what |
| 677 | * we hope is that we'll catch it via the master/target |
| 678 | * abort events. |
| 679 | */ |
| 680 | |
| 681 | if (error_bits & (PSYCHO_PCIAFSR_PPERR | PSYCHO_PCIAFSR_SPERR)) |
David S. Miller | 6c108f1 | 2007-05-07 23:49:01 -0700 | [diff] [blame] | 682 | pci_scan_for_parity_error(pbm, pbm->pci_bus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | |
| 684 | return IRQ_HANDLED; |
| 685 | } |
| 686 | |
| 687 | /* XXX What about PowerFail/PowerManagement??? -DaveM */ |
| 688 | #define PSYCHO_ECC_CTRL 0x0020 |
| 689 | #define PSYCHO_ECCCTRL_EE 0x8000000000000000UL /* Enable ECC Checking */ |
| 690 | #define PSYCHO_ECCCTRL_UE 0x4000000000000000UL /* Enable UE Interrupts */ |
| 691 | #define PSYCHO_ECCCTRL_CE 0x2000000000000000UL /* Enable CE INterrupts */ |
David S. Miller | 34768bc | 2007-05-07 23:06:27 -0700 | [diff] [blame] | 692 | static void psycho_register_error_handlers(struct pci_pbm_info *pbm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | { |
David S. Miller | 22fecba | 2008-09-10 00:19:28 -0700 | [diff] [blame] | 694 | struct of_device *op = of_find_device_by_node(pbm->op->node); |
David S. Miller | 34768bc | 2007-05-07 23:06:27 -0700 | [diff] [blame] | 695 | unsigned long base = pbm->controller_regs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | u64 tmp; |
David S. Miller | af80318 | 2007-05-08 17:23:31 -0700 | [diff] [blame] | 697 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | |
David S. Miller | 2b1e597 | 2006-06-29 15:07:37 -0700 | [diff] [blame] | 699 | if (!op) |
| 700 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | |
David S. Miller | 2b1e597 | 2006-06-29 15:07:37 -0700 | [diff] [blame] | 702 | /* Psycho interrupt property order is: |
David S. Miller | 34768bc | 2007-05-07 23:06:27 -0700 | [diff] [blame] | 703 | * 0: PCIERR INO for this PBM |
David S. Miller | 2b1e597 | 2006-06-29 15:07:37 -0700 | [diff] [blame] | 704 | * 1: UE ERR |
| 705 | * 2: CE ERR |
| 706 | * 3: POWER FAIL |
| 707 | * 4: SPARE HARDWARE |
David S. Miller | 34768bc | 2007-05-07 23:06:27 -0700 | [diff] [blame] | 708 | * 5: POWER MANAGEMENT |
David S. Miller | 2b1e597 | 2006-06-29 15:07:37 -0700 | [diff] [blame] | 709 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | |
David S. Miller | 2b1e597 | 2006-06-29 15:07:37 -0700 | [diff] [blame] | 711 | if (op->num_irqs < 6) |
| 712 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | |
David S. Miller | af80318 | 2007-05-08 17:23:31 -0700 | [diff] [blame] | 714 | /* We really mean to ignore the return result here. Two |
| 715 | * PCI controller share the same interrupt numbers and |
| 716 | * drive the same front-end hardware. Whichever of the |
| 717 | * two get in here first will register the IRQ handler |
| 718 | * the second will just error out since we do not pass in |
| 719 | * IRQF_SHARED. |
| 720 | */ |
| 721 | err = request_irq(op->irqs[1], psycho_ue_intr, 0, |
| 722 | "PSYCHO_UE", pbm); |
| 723 | err = request_irq(op->irqs[2], psycho_ce_intr, 0, |
| 724 | "PSYCHO_CE", pbm); |
| 725 | |
| 726 | /* This one, however, ought not to fail. We can just warn |
| 727 | * about it since the system can still operate properly even |
| 728 | * if this fails. |
| 729 | */ |
| 730 | err = request_irq(op->irqs[0], psycho_pcierr_intr, 0, |
| 731 | "PSYCHO_PCIERR", pbm); |
| 732 | if (err) |
| 733 | printk(KERN_WARNING "%s: Could not register PCIERR, " |
| 734 | "err=%d\n", pbm->name, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | |
| 736 | /* Enable UE and CE interrupts for controller. */ |
| 737 | psycho_write(base + PSYCHO_ECC_CTRL, |
| 738 | (PSYCHO_ECCCTRL_EE | |
| 739 | PSYCHO_ECCCTRL_UE | |
| 740 | PSYCHO_ECCCTRL_CE)); |
| 741 | |
| 742 | /* Enable PCI Error interrupts and clear error |
| 743 | * bits for each PBM. |
| 744 | */ |
| 745 | tmp = psycho_read(base + PSYCHO_PCIA_CTRL); |
| 746 | tmp |= (PSYCHO_PCICTRL_SERR | |
| 747 | PSYCHO_PCICTRL_SBH_ERR | |
| 748 | PSYCHO_PCICTRL_EEN); |
| 749 | tmp &= ~(PSYCHO_PCICTRL_SBH_INT); |
| 750 | psycho_write(base + PSYCHO_PCIA_CTRL, tmp); |
| 751 | |
| 752 | tmp = psycho_read(base + PSYCHO_PCIB_CTRL); |
| 753 | tmp |= (PSYCHO_PCICTRL_SERR | |
| 754 | PSYCHO_PCICTRL_SBH_ERR | |
| 755 | PSYCHO_PCICTRL_EEN); |
| 756 | tmp &= ~(PSYCHO_PCICTRL_SBH_INT); |
| 757 | psycho_write(base + PSYCHO_PCIB_CTRL, tmp); |
| 758 | } |
| 759 | |
| 760 | /* PSYCHO boot time probing and initialization. */ |
David S. Miller | 085ae41 | 2005-08-08 13:19:08 -0700 | [diff] [blame] | 761 | static void pbm_config_busmastering(struct pci_pbm_info *pbm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | { |
| 763 | u8 *addr; |
| 764 | |
| 765 | /* Set cache-line size to 64 bytes, this is actually |
| 766 | * a nop but I do it for completeness. |
| 767 | */ |
| 768 | addr = psycho_pci_config_mkaddr(pbm, pbm->pci_first_busno, |
| 769 | 0, PCI_CACHE_LINE_SIZE); |
| 770 | pci_config_write8(addr, 64 / sizeof(u32)); |
| 771 | |
| 772 | /* Set PBM latency timer to 64 PCI clocks. */ |
| 773 | addr = psycho_pci_config_mkaddr(pbm, pbm->pci_first_busno, |
| 774 | 0, PCI_LATENCY_TIMER); |
| 775 | pci_config_write8(addr, 64); |
| 776 | } |
| 777 | |
David S. Miller | e822358a | 2008-09-01 18:32:22 -0700 | [diff] [blame] | 778 | static void __init psycho_scan_bus(struct pci_pbm_info *pbm, |
| 779 | struct device *parent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | { |
David S. Miller | 34768bc | 2007-05-07 23:06:27 -0700 | [diff] [blame] | 781 | pbm_config_busmastering(pbm); |
| 782 | pbm->is_66mhz_capable = 0; |
David S. Miller | e822358a | 2008-09-01 18:32:22 -0700 | [diff] [blame] | 783 | pbm->pci_bus = pci_scan_one_pbm(pbm, parent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | |
| 785 | /* After the PCI bus scan is complete, we can register |
| 786 | * the error interrupt handlers. |
| 787 | */ |
David S. Miller | 34768bc | 2007-05-07 23:06:27 -0700 | [diff] [blame] | 788 | psycho_register_error_handlers(pbm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | } |
| 790 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | #define PSYCHO_IRQ_RETRY 0x1a00UL |
| 792 | #define PSYCHO_PCIA_DIAG 0x2020UL |
| 793 | #define PSYCHO_PCIB_DIAG 0x4020UL |
| 794 | #define PSYCHO_PCIDIAG_RESV 0xffffffffffffff80UL /* Reserved */ |
| 795 | #define PSYCHO_PCIDIAG_DRETRY 0x0000000000000040UL /* Disable retry limit */ |
| 796 | #define PSYCHO_PCIDIAG_DISYNC 0x0000000000000020UL /* Disable DMA wr / irq sync */ |
| 797 | #define PSYCHO_PCIDIAG_DDWSYNC 0x0000000000000010UL /* Disable DMA wr / PIO rd sync */ |
| 798 | #define PSYCHO_PCIDIAG_IDDPAR 0x0000000000000008UL /* Invert DMA data parity */ |
| 799 | #define PSYCHO_PCIDIAG_IPDPAR 0x0000000000000004UL /* Invert PIO data parity */ |
| 800 | #define PSYCHO_PCIDIAG_IPAPAR 0x0000000000000002UL /* Invert PIO address parity */ |
| 801 | #define PSYCHO_PCIDIAG_LPBACK 0x0000000000000001UL /* Enable loopback mode */ |
| 802 | |
David S. Miller | 28113a9 | 2007-05-08 00:19:02 -0700 | [diff] [blame] | 803 | static void psycho_controller_hwinit(struct pci_pbm_info *pbm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | { |
| 805 | u64 tmp; |
| 806 | |
David S. Miller | 28113a9 | 2007-05-08 00:19:02 -0700 | [diff] [blame] | 807 | psycho_write(pbm->controller_regs + PSYCHO_IRQ_RETRY, 5); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | |
| 809 | /* Enable arbiter for all PCI slots. */ |
David S. Miller | 28113a9 | 2007-05-08 00:19:02 -0700 | [diff] [blame] | 810 | tmp = psycho_read(pbm->controller_regs + PSYCHO_PCIA_CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | tmp |= PSYCHO_PCICTRL_AEN; |
David S. Miller | 28113a9 | 2007-05-08 00:19:02 -0700 | [diff] [blame] | 812 | psycho_write(pbm->controller_regs + PSYCHO_PCIA_CTRL, tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | |
David S. Miller | 28113a9 | 2007-05-08 00:19:02 -0700 | [diff] [blame] | 814 | tmp = psycho_read(pbm->controller_regs + PSYCHO_PCIB_CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | tmp |= PSYCHO_PCICTRL_AEN; |
David S. Miller | 28113a9 | 2007-05-08 00:19:02 -0700 | [diff] [blame] | 816 | psycho_write(pbm->controller_regs + PSYCHO_PCIB_CTRL, tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | |
| 818 | /* Disable DMA write / PIO read synchronization on |
| 819 | * both PCI bus segments. |
| 820 | * [ U2P Erratum 1243770, STP2223BGA data sheet ] |
| 821 | */ |
David S. Miller | 28113a9 | 2007-05-08 00:19:02 -0700 | [diff] [blame] | 822 | tmp = psycho_read(pbm->controller_regs + PSYCHO_PCIA_DIAG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | tmp |= PSYCHO_PCIDIAG_DDWSYNC; |
David S. Miller | 28113a9 | 2007-05-08 00:19:02 -0700 | [diff] [blame] | 824 | psycho_write(pbm->controller_regs + PSYCHO_PCIA_DIAG, tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | |
David S. Miller | 28113a9 | 2007-05-08 00:19:02 -0700 | [diff] [blame] | 826 | tmp = psycho_read(pbm->controller_regs + PSYCHO_PCIB_DIAG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | tmp |= PSYCHO_PCIDIAG_DDWSYNC; |
David S. Miller | 28113a9 | 2007-05-08 00:19:02 -0700 | [diff] [blame] | 828 | psycho_write(pbm->controller_regs + PSYCHO_PCIB_DIAG, tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | } |
| 830 | |
David S. Miller | 28113a9 | 2007-05-08 00:19:02 -0700 | [diff] [blame] | 831 | static void psycho_pbm_strbuf_init(struct pci_pbm_info *pbm, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | int is_pbm_a) |
| 833 | { |
| 834 | unsigned long base = pbm->controller_regs; |
| 835 | u64 control; |
| 836 | |
| 837 | if (is_pbm_a) { |
| 838 | pbm->stc.strbuf_control = base + PSYCHO_STRBUF_CONTROL_A; |
| 839 | pbm->stc.strbuf_pflush = base + PSYCHO_STRBUF_FLUSH_A; |
| 840 | pbm->stc.strbuf_fsync = base + PSYCHO_STRBUF_FSYNC_A; |
David S. Miller | d3ae4b5 | 2008-09-09 23:54:02 -0700 | [diff] [blame] | 841 | pbm->stc.strbuf_err_stat = base + PSYCHO_STC_ERR_A; |
| 842 | pbm->stc.strbuf_tag_diag = base + PSYCHO_STC_TAG_A; |
| 843 | pbm->stc.strbuf_line_diag= base + PSYCHO_STC_LINE_A; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | } else { |
| 845 | pbm->stc.strbuf_control = base + PSYCHO_STRBUF_CONTROL_B; |
| 846 | pbm->stc.strbuf_pflush = base + PSYCHO_STRBUF_FLUSH_B; |
| 847 | pbm->stc.strbuf_fsync = base + PSYCHO_STRBUF_FSYNC_B; |
David S. Miller | d3ae4b5 | 2008-09-09 23:54:02 -0700 | [diff] [blame] | 848 | pbm->stc.strbuf_err_stat = base + PSYCHO_STC_ERR_B; |
| 849 | pbm->stc.strbuf_tag_diag = base + PSYCHO_STC_TAG_B; |
| 850 | pbm->stc.strbuf_line_diag= base + PSYCHO_STC_LINE_B; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | } |
| 852 | /* PSYCHO's streaming buffer lacks ctx flushing. */ |
| 853 | pbm->stc.strbuf_ctxflush = 0; |
| 854 | pbm->stc.strbuf_ctxmatch_base = 0; |
| 855 | |
| 856 | pbm->stc.strbuf_flushflag = (volatile unsigned long *) |
| 857 | ((((unsigned long)&pbm->stc.__flushflag_buf[0]) |
| 858 | + 63UL) |
| 859 | & ~63UL); |
| 860 | pbm->stc.strbuf_flushflag_pa = (unsigned long) |
| 861 | __pa(pbm->stc.strbuf_flushflag); |
| 862 | |
| 863 | /* Enable the streaming buffer. We have to be careful |
| 864 | * just in case OBP left it with LRU locking enabled. |
| 865 | * |
| 866 | * It is possible to control if PBM will be rerun on |
| 867 | * line misses. Currently I just retain whatever setting |
| 868 | * OBP left us with. All checks so far show it having |
| 869 | * a value of zero. |
| 870 | */ |
| 871 | #undef PSYCHO_STRBUF_RERUN_ENABLE |
| 872 | #undef PSYCHO_STRBUF_RERUN_DISABLE |
| 873 | control = psycho_read(pbm->stc.strbuf_control); |
| 874 | control |= PSYCHO_STRBUF_CTRL_ENAB; |
| 875 | control &= ~(PSYCHO_STRBUF_CTRL_LENAB | PSYCHO_STRBUF_CTRL_LPTR); |
| 876 | #ifdef PSYCHO_STRBUF_RERUN_ENABLE |
| 877 | control &= ~(PSYCHO_STRBUF_CTRL_RRDIS); |
| 878 | #else |
| 879 | #ifdef PSYCHO_STRBUF_RERUN_DISABLE |
| 880 | control |= PSYCHO_STRBUF_CTRL_RRDIS; |
| 881 | #endif |
| 882 | #endif |
| 883 | psycho_write(pbm->stc.strbuf_control, control); |
| 884 | |
| 885 | pbm->stc.strbuf_enabled = 1; |
| 886 | } |
| 887 | |
| 888 | #define PSYCHO_IOSPACE_A 0x002000000UL |
| 889 | #define PSYCHO_IOSPACE_B 0x002010000UL |
| 890 | #define PSYCHO_IOSPACE_SIZE 0x00000ffffUL |
| 891 | #define PSYCHO_MEMSPACE_A 0x100000000UL |
| 892 | #define PSYCHO_MEMSPACE_B 0x180000000UL |
| 893 | #define PSYCHO_MEMSPACE_SIZE 0x07fffffffUL |
| 894 | |
David S. Miller | d3ae4b5 | 2008-09-09 23:54:02 -0700 | [diff] [blame] | 895 | static void __init psycho_pbm_init(struct pci_pbm_info *pbm, |
David S. Miller | e822358a | 2008-09-01 18:32:22 -0700 | [diff] [blame] | 896 | struct of_device *op, int is_pbm_a) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | { |
David S. Miller | e822358a | 2008-09-01 18:32:22 -0700 | [diff] [blame] | 898 | struct device_node *dp = op->node; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | |
David S. Miller | 34768bc | 2007-05-07 23:06:27 -0700 | [diff] [blame] | 900 | pbm->next = pci_pbm_root; |
| 901 | pci_pbm_root = pbm; |
| 902 | |
David S. Miller | c1b1a5f | 2008-03-19 04:52:48 -0700 | [diff] [blame] | 903 | pbm->numa_node = -1; |
| 904 | |
David S. Miller | ca3dd88 | 2007-05-09 02:35:27 -0700 | [diff] [blame] | 905 | pbm->pci_ops = &sun4u_pci_ops; |
| 906 | pbm->config_space_reg_bits = 8; |
David S. Miller | 34768bc | 2007-05-07 23:06:27 -0700 | [diff] [blame] | 907 | |
David S. Miller | 6c108f1 | 2007-05-07 23:49:01 -0700 | [diff] [blame] | 908 | pbm->index = pci_num_pbms++; |
| 909 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | pbm->chip_type = PBM_CHIP_TYPE_PSYCHO; |
David S. Miller | 0f73d1b | 2008-09-01 20:18:04 -0700 | [diff] [blame] | 911 | pbm->chip_version = of_getintprop_default(dp, "version#", 0); |
| 912 | pbm->chip_revision = of_getintprop_default(dp, "module-revision#", 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | |
David S. Miller | 22fecba | 2008-09-10 00:19:28 -0700 | [diff] [blame] | 914 | pbm->op = op; |
David S. Miller | e87dc35 | 2006-06-21 18:18:47 -0700 | [diff] [blame] | 915 | pbm->name = dp->full_name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | |
David S. Miller | b20bfe4 | 2008-08-30 03:13:20 -0700 | [diff] [blame] | 917 | printk(KERN_INFO "%s: PSYCHO PCI Bus Module ver[%x:%x]\n", |
David S. Miller | e87dc35 | 2006-06-21 18:18:47 -0700 | [diff] [blame] | 918 | pbm->name, |
| 919 | pbm->chip_version, pbm->chip_revision); |
| 920 | |
David S. Miller | 0f3e250 | 2007-03-15 21:44:03 -0700 | [diff] [blame] | 921 | pci_determine_mem_io_space(pbm); |
| 922 | |
David S. Miller | cfa0652 | 2007-05-07 21:51:41 -0700 | [diff] [blame] | 923 | pci_get_pbm_props(pbm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | |
David S. Miller | 28113a9 | 2007-05-08 00:19:02 -0700 | [diff] [blame] | 925 | psycho_pbm_strbuf_init(pbm, is_pbm_a); |
David S. Miller | b20bfe4 | 2008-08-30 03:13:20 -0700 | [diff] [blame] | 926 | |
David S. Miller | e822358a | 2008-09-01 18:32:22 -0700 | [diff] [blame] | 927 | psycho_scan_bus(pbm, &op->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | } |
| 929 | |
David S. Miller | d3ae4b5 | 2008-09-09 23:54:02 -0700 | [diff] [blame] | 930 | static struct pci_pbm_info * __devinit psycho_find_sibling(u32 upa_portid) |
| 931 | { |
| 932 | struct pci_pbm_info *pbm; |
| 933 | |
| 934 | for (pbm = pci_pbm_root; pbm; pbm = pbm->next) { |
| 935 | if (pbm->portid == upa_portid) |
| 936 | return pbm; |
| 937 | } |
| 938 | return NULL; |
| 939 | } |
| 940 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | #define PSYCHO_CONFIGSPACE 0x001000000UL |
| 942 | |
David S. Miller | b20bfe4 | 2008-08-30 03:13:20 -0700 | [diff] [blame] | 943 | static int __devinit psycho_probe(struct of_device *op, |
| 944 | const struct of_device_id *match) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | { |
David S. Miller | b20bfe4 | 2008-08-30 03:13:20 -0700 | [diff] [blame] | 946 | const struct linux_prom64_registers *pr_regs; |
| 947 | struct device_node *dp = op->node; |
David S. Miller | 34768bc | 2007-05-07 23:06:27 -0700 | [diff] [blame] | 948 | struct pci_pbm_info *pbm; |
David S. Miller | 16ce82d | 2007-04-26 21:08:21 -0700 | [diff] [blame] | 949 | struct iommu *iommu; |
David S. Miller | b20bfe4 | 2008-08-30 03:13:20 -0700 | [diff] [blame] | 950 | int is_pbm_a, err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | u32 upa_portid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | |
David S. Miller | 0f73d1b | 2008-09-01 20:18:04 -0700 | [diff] [blame] | 953 | upa_portid = of_getintprop_default(dp, "upa-portid", 0xff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | |
David S. Miller | b20bfe4 | 2008-08-30 03:13:20 -0700 | [diff] [blame] | 955 | err = -ENOMEM; |
David S. Miller | d3ae4b5 | 2008-09-09 23:54:02 -0700 | [diff] [blame] | 956 | pbm = kzalloc(sizeof(*pbm), GFP_KERNEL); |
| 957 | if (!pbm) { |
| 958 | printk(KERN_ERR PFX "Cannot allocate pci_pbm_info.\n"); |
David S. Miller | d7472c3 | 2008-08-31 01:33:52 -0700 | [diff] [blame] | 959 | goto out_err; |
David S. Miller | b20bfe4 | 2008-08-30 03:13:20 -0700 | [diff] [blame] | 960 | } |
| 961 | |
David S. Miller | d3ae4b5 | 2008-09-09 23:54:02 -0700 | [diff] [blame] | 962 | pbm->sibling = psycho_find_sibling(upa_portid); |
| 963 | if (pbm->sibling) { |
| 964 | iommu = pbm->sibling->iommu; |
| 965 | } else { |
| 966 | iommu = kzalloc(sizeof(struct iommu), GFP_KERNEL); |
| 967 | if (!iommu) { |
| 968 | printk(KERN_ERR PFX "Cannot allocate PBM iommu.\n"); |
| 969 | goto out_free_controller; |
| 970 | } |
David S. Miller | b20bfe4 | 2008-08-30 03:13:20 -0700 | [diff] [blame] | 971 | } |
David S. Miller | ad7ad57 | 2007-07-27 22:39:14 -0700 | [diff] [blame] | 972 | |
David S. Miller | d3ae4b5 | 2008-09-09 23:54:02 -0700 | [diff] [blame] | 973 | pbm->iommu = iommu; |
| 974 | pbm->portid = upa_portid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | |
David S. Miller | b20bfe4 | 2008-08-30 03:13:20 -0700 | [diff] [blame] | 976 | pr_regs = of_get_property(dp, "reg", NULL); |
| 977 | err = -ENODEV; |
| 978 | if (!pr_regs) { |
| 979 | printk(KERN_ERR PFX "No reg property.\n"); |
David S. Miller | d7472c3 | 2008-08-31 01:33:52 -0700 | [diff] [blame] | 980 | goto out_free_iommu; |
David S. Miller | b20bfe4 | 2008-08-30 03:13:20 -0700 | [diff] [blame] | 981 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | is_pbm_a = ((pr_regs[0].phys_addr & 0x6000) == 0x2000); |
David S. Miller | ad7ad57 | 2007-07-27 22:39:14 -0700 | [diff] [blame] | 984 | |
David S. Miller | d3ae4b5 | 2008-09-09 23:54:02 -0700 | [diff] [blame] | 985 | pbm->controller_regs = pr_regs[2].phys_addr; |
| 986 | pbm->config_space = (pr_regs[2].phys_addr + PSYCHO_CONFIGSPACE); |
| 987 | |
| 988 | if (is_pbm_a) { |
| 989 | pbm->pci_afsr = pbm->controller_regs + PSYCHO_PCI_AFSR_A; |
| 990 | pbm->pci_afar = pbm->controller_regs + PSYCHO_PCI_AFAR_A; |
| 991 | pbm->pci_csr = pbm->controller_regs + PSYCHO_PCIA_CTRL; |
| 992 | } else { |
| 993 | pbm->pci_afsr = pbm->controller_regs + PSYCHO_PCI_AFSR_B; |
| 994 | pbm->pci_afar = pbm->controller_regs + PSYCHO_PCI_AFAR_B; |
| 995 | pbm->pci_csr = pbm->controller_regs + PSYCHO_PCIB_CTRL; |
| 996 | } |
| 997 | |
| 998 | psycho_controller_hwinit(pbm); |
| 999 | if (!pbm->sibling) { |
David S. Miller | a21cff3 | 2008-09-10 03:07:03 -0700 | [diff] [blame^] | 1000 | err = psycho_iommu_init(pbm, 128, 0xc0000000, |
| 1001 | 0xffffffff, PSYCHO_CONTROL); |
David S. Miller | d3ae4b5 | 2008-09-09 23:54:02 -0700 | [diff] [blame] | 1002 | if (err) |
| 1003 | goto out_free_iommu; |
David S. Miller | a21cff3 | 2008-09-10 03:07:03 -0700 | [diff] [blame^] | 1004 | |
| 1005 | /* If necessary, hook us up for starfire IRQ translations. */ |
| 1006 | if (this_is_starfire) |
| 1007 | starfire_hookup(pbm->portid); |
David S. Miller | d3ae4b5 | 2008-09-09 23:54:02 -0700 | [diff] [blame] | 1008 | } |
| 1009 | |
| 1010 | psycho_pbm_init(pbm, op, is_pbm_a); |
| 1011 | |
| 1012 | if (pbm->sibling) |
| 1013 | pbm->sibling->sibling = pbm; |
| 1014 | |
| 1015 | dev_set_drvdata(&op->dev, pbm); |
David S. Miller | b20bfe4 | 2008-08-30 03:13:20 -0700 | [diff] [blame] | 1016 | |
| 1017 | return 0; |
| 1018 | |
David S. Miller | d7472c3 | 2008-08-31 01:33:52 -0700 | [diff] [blame] | 1019 | out_free_iommu: |
David S. Miller | d3ae4b5 | 2008-09-09 23:54:02 -0700 | [diff] [blame] | 1020 | if (!pbm->sibling) |
| 1021 | kfree(pbm->iommu); |
David S. Miller | d7472c3 | 2008-08-31 01:33:52 -0700 | [diff] [blame] | 1022 | |
| 1023 | out_free_controller: |
David S. Miller | d3ae4b5 | 2008-09-09 23:54:02 -0700 | [diff] [blame] | 1024 | kfree(pbm); |
David S. Miller | d7472c3 | 2008-08-31 01:33:52 -0700 | [diff] [blame] | 1025 | |
| 1026 | out_err: |
David S. Miller | b20bfe4 | 2008-08-30 03:13:20 -0700 | [diff] [blame] | 1027 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | } |
David S. Miller | b20bfe4 | 2008-08-30 03:13:20 -0700 | [diff] [blame] | 1029 | |
David S. Miller | fd09831 | 2008-08-31 01:23:17 -0700 | [diff] [blame] | 1030 | static struct of_device_id __initdata psycho_match[] = { |
David S. Miller | b20bfe4 | 2008-08-30 03:13:20 -0700 | [diff] [blame] | 1031 | { |
| 1032 | .name = "pci", |
| 1033 | .compatible = "pci108e,8000", |
| 1034 | }, |
| 1035 | {}, |
| 1036 | }; |
| 1037 | |
| 1038 | static struct of_platform_driver psycho_driver = { |
| 1039 | .name = DRIVER_NAME, |
| 1040 | .match_table = psycho_match, |
| 1041 | .probe = psycho_probe, |
| 1042 | }; |
| 1043 | |
| 1044 | static int __init psycho_init(void) |
| 1045 | { |
| 1046 | return of_register_driver(&psycho_driver, &of_bus_type); |
| 1047 | } |
| 1048 | |
| 1049 | subsys_initcall(psycho_init); |