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