| 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> | 
| David S. Miller | 87395fc | 2008-09-10 04:13:10 -0700 | [diff] [blame] | 20 | #include <asm/upa.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 |  | 
|  | 22 | #include "pci_impl.h" | 
|  | 23 | #include "iommu_common.h" | 
| David S. Miller | a21cff3 | 2008-09-10 03:07:03 -0700 | [diff] [blame] | 24 | #include "psycho_common.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 |  | 
| David S. Miller | b20bfe4 | 2008-08-30 03:13:20 -0700 | [diff] [blame] | 26 | #define DRIVER_NAME	"psycho" | 
|  | 27 | #define PFX		DRIVER_NAME ": " | 
|  | 28 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | /* Misc. PSYCHO PCI controller register offsets and definitions. */ | 
|  | 30 | #define PSYCHO_CONTROL		0x0010UL | 
|  | 31 | #define  PSYCHO_CONTROL_IMPL	 0xf000000000000000UL /* Implementation of this PSYCHO*/ | 
|  | 32 | #define  PSYCHO_CONTROL_VER	 0x0f00000000000000UL /* Version of this PSYCHO       */ | 
|  | 33 | #define  PSYCHO_CONTROL_MID	 0x00f8000000000000UL /* UPA Module ID of PSYCHO      */ | 
|  | 34 | #define  PSYCHO_CONTROL_IGN	 0x0007c00000000000UL /* Interrupt Group Number       */ | 
|  | 35 | #define  PSYCHO_CONTROL_RESV     0x00003ffffffffff0UL /* Reserved                     */ | 
|  | 36 | #define  PSYCHO_CONTROL_APCKEN	 0x0000000000000008UL /* Address Parity Check Enable  */ | 
|  | 37 | #define  PSYCHO_CONTROL_APERR	 0x0000000000000004UL /* Incoming System Addr Parerr  */ | 
|  | 38 | #define  PSYCHO_CONTROL_IAP	 0x0000000000000002UL /* Invert UPA Parity            */ | 
|  | 39 | #define  PSYCHO_CONTROL_MODE	 0x0000000000000001UL /* PSYCHO clock mode            */ | 
|  | 40 | #define PSYCHO_PCIA_CTRL	0x2000UL | 
|  | 41 | #define PSYCHO_PCIB_CTRL	0x4000UL | 
|  | 42 | #define  PSYCHO_PCICTRL_RESV1	 0xfffffff000000000UL /* Reserved                     */ | 
|  | 43 | #define  PSYCHO_PCICTRL_SBH_ERR	 0x0000000800000000UL /* Streaming byte hole error    */ | 
|  | 44 | #define  PSYCHO_PCICTRL_SERR	 0x0000000400000000UL /* SERR signal asserted         */ | 
|  | 45 | #define  PSYCHO_PCICTRL_SPEED	 0x0000000200000000UL /* PCI speed (1 is U2P clock)   */ | 
|  | 46 | #define  PSYCHO_PCICTRL_RESV2	 0x00000001ffc00000UL /* Reserved                     */ | 
|  | 47 | #define  PSYCHO_PCICTRL_ARB_PARK 0x0000000000200000UL /* PCI arbitration parking      */ | 
|  | 48 | #define  PSYCHO_PCICTRL_RESV3	 0x00000000001ff800UL /* Reserved                     */ | 
|  | 49 | #define  PSYCHO_PCICTRL_SBH_INT	 0x0000000000000400UL /* Streaming byte hole int enab */ | 
|  | 50 | #define  PSYCHO_PCICTRL_WEN	 0x0000000000000200UL /* Power Mgmt Wake Enable       */ | 
|  | 51 | #define  PSYCHO_PCICTRL_EEN	 0x0000000000000100UL /* PCI Error Interrupt Enable   */ | 
|  | 52 | #define  PSYCHO_PCICTRL_RESV4	 0x00000000000000c0UL /* Reserved                     */ | 
|  | 53 | #define  PSYCHO_PCICTRL_AEN	 0x000000000000003fUL /* PCI DVMA Arbitration Enable  */ | 
|  | 54 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | /* PSYCHO error handling support. */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 |  | 
|  | 57 | /* Helper function of IOMMU error checking, which checks out | 
|  | 58 | * the state of the streaming buffers.  The IOMMU lock is | 
|  | 59 | * held when this is called. | 
|  | 60 | * | 
|  | 61 | * For the PCI error case we know which PBM (and thus which | 
|  | 62 | * streaming buffer) caused the error, but for the uncorrectable | 
|  | 63 | * error case we do not.  So we always check both streaming caches. | 
|  | 64 | */ | 
|  | 65 | #define PSYCHO_STRBUF_CONTROL_A 0x2800UL | 
|  | 66 | #define PSYCHO_STRBUF_CONTROL_B 0x4800UL | 
|  | 67 | #define  PSYCHO_STRBUF_CTRL_LPTR    0x00000000000000f0UL /* LRU Lock Pointer */ | 
|  | 68 | #define  PSYCHO_STRBUF_CTRL_LENAB   0x0000000000000008UL /* LRU Lock Enable */ | 
|  | 69 | #define  PSYCHO_STRBUF_CTRL_RRDIS   0x0000000000000004UL /* Rerun Disable */ | 
|  | 70 | #define  PSYCHO_STRBUF_CTRL_DENAB   0x0000000000000002UL /* Diagnostic Mode Enable */ | 
|  | 71 | #define  PSYCHO_STRBUF_CTRL_ENAB    0x0000000000000001UL /* Streaming Buffer Enable */ | 
|  | 72 | #define PSYCHO_STRBUF_FLUSH_A   0x2808UL | 
|  | 73 | #define PSYCHO_STRBUF_FLUSH_B   0x4808UL | 
|  | 74 | #define PSYCHO_STRBUF_FSYNC_A   0x2810UL | 
|  | 75 | #define PSYCHO_STRBUF_FSYNC_B   0x4810UL | 
|  | 76 | #define PSYCHO_STC_DATA_A	0xb000UL | 
|  | 77 | #define PSYCHO_STC_DATA_B	0xc000UL | 
|  | 78 | #define PSYCHO_STC_ERR_A	0xb400UL | 
|  | 79 | #define PSYCHO_STC_ERR_B	0xc400UL | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | #define PSYCHO_STC_TAG_A	0xb800UL | 
|  | 81 | #define PSYCHO_STC_TAG_B	0xc800UL | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | #define PSYCHO_STC_LINE_A	0xb900UL | 
|  | 83 | #define PSYCHO_STC_LINE_B	0xc900UL | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | /* When an Uncorrectable Error or a PCI Error happens, we | 
|  | 86 | * interrogate the IOMMU state to see if it is the cause. | 
|  | 87 | */ | 
|  | 88 | #define PSYCHO_IOMMU_CONTROL	0x0200UL | 
|  | 89 | #define  PSYCHO_IOMMU_CTRL_RESV     0xfffffffff9000000UL /* Reserved                      */ | 
|  | 90 | #define  PSYCHO_IOMMU_CTRL_XLTESTAT 0x0000000006000000UL /* Translation Error Status      */ | 
|  | 91 | #define  PSYCHO_IOMMU_CTRL_XLTEERR  0x0000000001000000UL /* Translation Error encountered */ | 
|  | 92 | #define  PSYCHO_IOMMU_CTRL_LCKEN    0x0000000000800000UL /* Enable translation locking    */ | 
|  | 93 | #define  PSYCHO_IOMMU_CTRL_LCKPTR   0x0000000000780000UL /* Translation lock pointer      */ | 
|  | 94 | #define  PSYCHO_IOMMU_CTRL_TSBSZ    0x0000000000070000UL /* TSB Size                      */ | 
|  | 95 | #define  PSYCHO_IOMMU_TSBSZ_1K      0x0000000000000000UL /* TSB Table 1024 8-byte entries */ | 
|  | 96 | #define  PSYCHO_IOMMU_TSBSZ_2K      0x0000000000010000UL /* TSB Table 2048 8-byte entries */ | 
|  | 97 | #define  PSYCHO_IOMMU_TSBSZ_4K      0x0000000000020000UL /* TSB Table 4096 8-byte entries */ | 
|  | 98 | #define  PSYCHO_IOMMU_TSBSZ_8K      0x0000000000030000UL /* TSB Table 8192 8-byte entries */ | 
|  | 99 | #define  PSYCHO_IOMMU_TSBSZ_16K     0x0000000000040000UL /* TSB Table 16k 8-byte entries  */ | 
|  | 100 | #define  PSYCHO_IOMMU_TSBSZ_32K     0x0000000000050000UL /* TSB Table 32k 8-byte entries  */ | 
|  | 101 | #define  PSYCHO_IOMMU_TSBSZ_64K     0x0000000000060000UL /* TSB Table 64k 8-byte entries  */ | 
|  | 102 | #define  PSYCHO_IOMMU_TSBSZ_128K    0x0000000000070000UL /* TSB Table 128k 8-byte entries */ | 
|  | 103 | #define  PSYCHO_IOMMU_CTRL_RESV2    0x000000000000fff8UL /* Reserved                      */ | 
|  | 104 | #define  PSYCHO_IOMMU_CTRL_TBWSZ    0x0000000000000004UL /* Assumed page size, 0=8k 1=64k */ | 
|  | 105 | #define  PSYCHO_IOMMU_CTRL_DENAB    0x0000000000000002UL /* Diagnostic mode enable        */ | 
|  | 106 | #define  PSYCHO_IOMMU_CTRL_ENAB     0x0000000000000001UL /* IOMMU Enable                  */ | 
|  | 107 | #define PSYCHO_IOMMU_TSBBASE	0x0208UL | 
|  | 108 | #define PSYCHO_IOMMU_FLUSH	0x0210UL | 
|  | 109 | #define PSYCHO_IOMMU_TAG	0xa580UL | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | #define PSYCHO_IOMMU_DATA	0xa600UL | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 |  | 
|  | 112 | /* Uncorrectable Errors.  Cause of the error and the address are | 
|  | 113 | * recorded in the UE_AFSR and UE_AFAR of PSYCHO.  They are errors | 
|  | 114 | * relating to UPA interface transactions. | 
|  | 115 | */ | 
|  | 116 | #define PSYCHO_UE_AFSR	0x0030UL | 
|  | 117 | #define  PSYCHO_UEAFSR_PPIO	0x8000000000000000UL /* Primary PIO is cause         */ | 
|  | 118 | #define  PSYCHO_UEAFSR_PDRD	0x4000000000000000UL /* Primary DVMA read is cause   */ | 
|  | 119 | #define  PSYCHO_UEAFSR_PDWR	0x2000000000000000UL /* Primary DVMA write is cause  */ | 
|  | 120 | #define  PSYCHO_UEAFSR_SPIO	0x1000000000000000UL /* Secondary PIO is cause       */ | 
|  | 121 | #define  PSYCHO_UEAFSR_SDRD	0x0800000000000000UL /* Secondary DVMA read is cause */ | 
|  | 122 | #define  PSYCHO_UEAFSR_SDWR	0x0400000000000000UL /* Secondary DVMA write is cause*/ | 
|  | 123 | #define  PSYCHO_UEAFSR_RESV1	0x03ff000000000000UL /* Reserved                     */ | 
|  | 124 | #define  PSYCHO_UEAFSR_BMSK	0x0000ffff00000000UL /* Bytemask of failed transfer  */ | 
|  | 125 | #define  PSYCHO_UEAFSR_DOFF	0x00000000e0000000UL /* Doubleword Offset            */ | 
|  | 126 | #define  PSYCHO_UEAFSR_MID	0x000000001f000000UL /* UPA MID causing the fault    */ | 
|  | 127 | #define  PSYCHO_UEAFSR_BLK	0x0000000000800000UL /* Trans was block operation    */ | 
|  | 128 | #define  PSYCHO_UEAFSR_RESV2	0x00000000007fffffUL /* Reserved                     */ | 
|  | 129 | #define PSYCHO_UE_AFAR	0x0038UL | 
|  | 130 |  | 
| Al Viro | 6d24c8d | 2006-10-08 08:23:28 -0400 | [diff] [blame] | 131 | static irqreturn_t psycho_ue_intr(int irq, void *dev_id) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | { | 
| David S. Miller | 34768bc | 2007-05-07 23:06:27 -0700 | [diff] [blame] | 133 | struct pci_pbm_info *pbm = dev_id; | 
| David S. Miller | 34768bc | 2007-05-07 23:06:27 -0700 | [diff] [blame] | 134 | unsigned long afsr_reg = pbm->controller_regs + PSYCHO_UE_AFSR; | 
|  | 135 | unsigned long afar_reg = pbm->controller_regs + PSYCHO_UE_AFAR; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | unsigned long afsr, afar, error_bits; | 
|  | 137 | int reported; | 
|  | 138 |  | 
|  | 139 | /* Latch uncorrectable error status. */ | 
| David S. Miller | 87395fc | 2008-09-10 04:13:10 -0700 | [diff] [blame] | 140 | afar = upa_readq(afar_reg); | 
|  | 141 | afsr = upa_readq(afsr_reg); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 |  | 
|  | 143 | /* Clear the primary/secondary error status bits. */ | 
|  | 144 | error_bits = afsr & | 
|  | 145 | (PSYCHO_UEAFSR_PPIO | PSYCHO_UEAFSR_PDRD | PSYCHO_UEAFSR_PDWR | | 
|  | 146 | PSYCHO_UEAFSR_SPIO | PSYCHO_UEAFSR_SDRD | PSYCHO_UEAFSR_SDWR); | 
|  | 147 | if (!error_bits) | 
|  | 148 | return IRQ_NONE; | 
| David S. Miller | 87395fc | 2008-09-10 04:13:10 -0700 | [diff] [blame] | 149 | upa_writeq(error_bits, afsr_reg); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 |  | 
|  | 151 | /* Log the error. */ | 
| David S. Miller | 6c108f1 | 2007-05-07 23:49:01 -0700 | [diff] [blame] | 152 | printk("%s: Uncorrectable Error, primary error type[%s]\n", | 
|  | 153 | pbm->name, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | (((error_bits & PSYCHO_UEAFSR_PPIO) ? | 
|  | 155 | "PIO" : | 
|  | 156 | ((error_bits & PSYCHO_UEAFSR_PDRD) ? | 
|  | 157 | "DMA Read" : | 
|  | 158 | ((error_bits & PSYCHO_UEAFSR_PDWR) ? | 
|  | 159 | "DMA Write" : "???"))))); | 
| David S. Miller | 6c108f1 | 2007-05-07 23:49:01 -0700 | [diff] [blame] | 160 | printk("%s: bytemask[%04lx] dword_offset[%lx] UPA_MID[%02lx] was_block(%d)\n", | 
|  | 161 | pbm->name, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | (afsr & PSYCHO_UEAFSR_BMSK) >> 32UL, | 
|  | 163 | (afsr & PSYCHO_UEAFSR_DOFF) >> 29UL, | 
|  | 164 | (afsr & PSYCHO_UEAFSR_MID) >> 24UL, | 
|  | 165 | ((afsr & PSYCHO_UEAFSR_BLK) ? 1 : 0)); | 
| David S. Miller | 6c108f1 | 2007-05-07 23:49:01 -0700 | [diff] [blame] | 166 | printk("%s: UE AFAR [%016lx]\n", pbm->name, afar); | 
|  | 167 | printk("%s: UE Secondary errors [", pbm->name); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | reported = 0; | 
|  | 169 | if (afsr & PSYCHO_UEAFSR_SPIO) { | 
|  | 170 | reported++; | 
|  | 171 | printk("(PIO)"); | 
|  | 172 | } | 
|  | 173 | if (afsr & PSYCHO_UEAFSR_SDRD) { | 
|  | 174 | reported++; | 
|  | 175 | printk("(DMA Read)"); | 
|  | 176 | } | 
|  | 177 | if (afsr & PSYCHO_UEAFSR_SDWR) { | 
|  | 178 | reported++; | 
|  | 179 | printk("(DMA Write)"); | 
|  | 180 | } | 
|  | 181 | if (!reported) | 
|  | 182 | printk("(none)"); | 
|  | 183 | printk("]\n"); | 
|  | 184 |  | 
| David S. Miller | 34768bc | 2007-05-07 23:06:27 -0700 | [diff] [blame] | 185 | /* Interrogate both IOMMUs for error status. */ | 
| David S. Miller | d3ae4b5 | 2008-09-09 23:54:02 -0700 | [diff] [blame] | 186 | psycho_check_iommu_error(pbm, afsr, afar, UE_ERR); | 
|  | 187 | if (pbm->sibling) | 
|  | 188 | psycho_check_iommu_error(pbm->sibling, afsr, afar, UE_ERR); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 |  | 
|  | 190 | return IRQ_HANDLED; | 
|  | 191 | } | 
|  | 192 |  | 
|  | 193 | /* Correctable Errors. */ | 
|  | 194 | #define PSYCHO_CE_AFSR	0x0040UL | 
|  | 195 | #define  PSYCHO_CEAFSR_PPIO	0x8000000000000000UL /* Primary PIO is cause         */ | 
|  | 196 | #define  PSYCHO_CEAFSR_PDRD	0x4000000000000000UL /* Primary DVMA read is cause   */ | 
|  | 197 | #define  PSYCHO_CEAFSR_PDWR	0x2000000000000000UL /* Primary DVMA write is cause  */ | 
|  | 198 | #define  PSYCHO_CEAFSR_SPIO	0x1000000000000000UL /* Secondary PIO is cause       */ | 
|  | 199 | #define  PSYCHO_CEAFSR_SDRD	0x0800000000000000UL /* Secondary DVMA read is cause */ | 
|  | 200 | #define  PSYCHO_CEAFSR_SDWR	0x0400000000000000UL /* Secondary DVMA write is cause*/ | 
|  | 201 | #define  PSYCHO_CEAFSR_RESV1	0x0300000000000000UL /* Reserved                     */ | 
|  | 202 | #define  PSYCHO_CEAFSR_ESYND	0x00ff000000000000UL /* Syndrome Bits                */ | 
|  | 203 | #define  PSYCHO_CEAFSR_BMSK	0x0000ffff00000000UL /* Bytemask of failed transfer  */ | 
|  | 204 | #define  PSYCHO_CEAFSR_DOFF	0x00000000e0000000UL /* Double Offset                */ | 
|  | 205 | #define  PSYCHO_CEAFSR_MID	0x000000001f000000UL /* UPA MID causing the fault    */ | 
|  | 206 | #define  PSYCHO_CEAFSR_BLK	0x0000000000800000UL /* Trans was block operation    */ | 
|  | 207 | #define  PSYCHO_CEAFSR_RESV2	0x00000000007fffffUL /* Reserved                     */ | 
|  | 208 | #define PSYCHO_CE_AFAR	0x0040UL | 
|  | 209 |  | 
| Al Viro | 6d24c8d | 2006-10-08 08:23:28 -0400 | [diff] [blame] | 210 | static irqreturn_t psycho_ce_intr(int irq, void *dev_id) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | { | 
| David S. Miller | 34768bc | 2007-05-07 23:06:27 -0700 | [diff] [blame] | 212 | struct pci_pbm_info *pbm = dev_id; | 
| David S. Miller | 34768bc | 2007-05-07 23:06:27 -0700 | [diff] [blame] | 213 | unsigned long afsr_reg = pbm->controller_regs + PSYCHO_CE_AFSR; | 
|  | 214 | unsigned long afar_reg = pbm->controller_regs + PSYCHO_CE_AFAR; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | unsigned long afsr, afar, error_bits; | 
|  | 216 | int reported; | 
|  | 217 |  | 
|  | 218 | /* Latch error status. */ | 
| David S. Miller | 87395fc | 2008-09-10 04:13:10 -0700 | [diff] [blame] | 219 | afar = upa_readq(afar_reg); | 
|  | 220 | afsr = upa_readq(afsr_reg); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 |  | 
|  | 222 | /* Clear primary/secondary error status bits. */ | 
|  | 223 | error_bits = afsr & | 
|  | 224 | (PSYCHO_CEAFSR_PPIO | PSYCHO_CEAFSR_PDRD | PSYCHO_CEAFSR_PDWR | | 
|  | 225 | PSYCHO_CEAFSR_SPIO | PSYCHO_CEAFSR_SDRD | PSYCHO_CEAFSR_SDWR); | 
|  | 226 | if (!error_bits) | 
|  | 227 | return IRQ_NONE; | 
| David S. Miller | 87395fc | 2008-09-10 04:13:10 -0700 | [diff] [blame] | 228 | upa_writeq(error_bits, afsr_reg); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 |  | 
|  | 230 | /* Log the error. */ | 
| David S. Miller | 6c108f1 | 2007-05-07 23:49:01 -0700 | [diff] [blame] | 231 | printk("%s: Correctable Error, primary error type[%s]\n", | 
|  | 232 | pbm->name, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | (((error_bits & PSYCHO_CEAFSR_PPIO) ? | 
|  | 234 | "PIO" : | 
|  | 235 | ((error_bits & PSYCHO_CEAFSR_PDRD) ? | 
|  | 236 | "DMA Read" : | 
|  | 237 | ((error_bits & PSYCHO_CEAFSR_PDWR) ? | 
|  | 238 | "DMA Write" : "???"))))); | 
|  | 239 |  | 
|  | 240 | /* XXX Use syndrome and afar to print out module string just like | 
|  | 241 | * XXX UDB CE trap handler does... -DaveM | 
|  | 242 | */ | 
| David S. Miller | 6c108f1 | 2007-05-07 23:49:01 -0700 | [diff] [blame] | 243 | printk("%s: syndrome[%02lx] bytemask[%04lx] dword_offset[%lx] " | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | "UPA_MID[%02lx] was_block(%d)\n", | 
| David S. Miller | 6c108f1 | 2007-05-07 23:49:01 -0700 | [diff] [blame] | 245 | pbm->name, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | (afsr & PSYCHO_CEAFSR_ESYND) >> 48UL, | 
|  | 247 | (afsr & PSYCHO_CEAFSR_BMSK) >> 32UL, | 
|  | 248 | (afsr & PSYCHO_CEAFSR_DOFF) >> 29UL, | 
|  | 249 | (afsr & PSYCHO_CEAFSR_MID) >> 24UL, | 
|  | 250 | ((afsr & PSYCHO_CEAFSR_BLK) ? 1 : 0)); | 
| David S. Miller | 6c108f1 | 2007-05-07 23:49:01 -0700 | [diff] [blame] | 251 | printk("%s: CE AFAR [%016lx]\n", pbm->name, afar); | 
|  | 252 | printk("%s: CE Secondary errors [", pbm->name); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | reported = 0; | 
|  | 254 | if (afsr & PSYCHO_CEAFSR_SPIO) { | 
|  | 255 | reported++; | 
|  | 256 | printk("(PIO)"); | 
|  | 257 | } | 
|  | 258 | if (afsr & PSYCHO_CEAFSR_SDRD) { | 
|  | 259 | reported++; | 
|  | 260 | printk("(DMA Read)"); | 
|  | 261 | } | 
|  | 262 | if (afsr & PSYCHO_CEAFSR_SDWR) { | 
|  | 263 | reported++; | 
|  | 264 | printk("(DMA Write)"); | 
|  | 265 | } | 
|  | 266 | if (!reported) | 
|  | 267 | printk("(none)"); | 
|  | 268 | printk("]\n"); | 
|  | 269 |  | 
|  | 270 | return IRQ_HANDLED; | 
|  | 271 | } | 
|  | 272 |  | 
|  | 273 | /* PCI Errors.  They are signalled by the PCI bus module since they | 
|  | 274 | * are associated with a specific bus segment. | 
|  | 275 | */ | 
|  | 276 | #define PSYCHO_PCI_AFSR_A	0x2010UL | 
|  | 277 | #define PSYCHO_PCI_AFSR_B	0x4010UL | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | #define PSYCHO_PCI_AFAR_A	0x2018UL | 
|  | 279 | #define PSYCHO_PCI_AFAR_B	0x4018UL | 
|  | 280 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | /* XXX What about PowerFail/PowerManagement??? -DaveM */ | 
|  | 282 | #define PSYCHO_ECC_CTRL		0x0020 | 
|  | 283 | #define  PSYCHO_ECCCTRL_EE	 0x8000000000000000UL /* Enable ECC Checking */ | 
|  | 284 | #define  PSYCHO_ECCCTRL_UE	 0x4000000000000000UL /* Enable UE Interrupts */ | 
|  | 285 | #define  PSYCHO_ECCCTRL_CE	 0x2000000000000000UL /* Enable CE INterrupts */ | 
| David S. Miller | 34768bc | 2007-05-07 23:06:27 -0700 | [diff] [blame] | 286 | static void psycho_register_error_handlers(struct pci_pbm_info *pbm) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | { | 
| Grant Likely | cd4cd73 | 2010-07-22 16:04:30 -0600 | [diff] [blame] | 288 | struct platform_device *op = of_find_device_by_node(pbm->op->dev.of_node); | 
| David S. Miller | 34768bc | 2007-05-07 23:06:27 -0700 | [diff] [blame] | 289 | unsigned long base = pbm->controller_regs; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | u64 tmp; | 
| David S. Miller | af80318 | 2007-05-08 17:23:31 -0700 | [diff] [blame] | 291 | int err; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 |  | 
| David S. Miller | 2b1e597 | 2006-06-29 15:07:37 -0700 | [diff] [blame] | 293 | if (!op) | 
|  | 294 | return; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 |  | 
| David S. Miller | 2b1e597 | 2006-06-29 15:07:37 -0700 | [diff] [blame] | 296 | /* Psycho interrupt property order is: | 
| David S. Miller | 34768bc | 2007-05-07 23:06:27 -0700 | [diff] [blame] | 297 | * 0: PCIERR INO for this PBM | 
| David S. Miller | 2b1e597 | 2006-06-29 15:07:37 -0700 | [diff] [blame] | 298 | * 1: UE ERR | 
|  | 299 | * 2: CE ERR | 
|  | 300 | * 3: POWER FAIL | 
|  | 301 | * 4: SPARE HARDWARE | 
| David S. Miller | 34768bc | 2007-05-07 23:06:27 -0700 | [diff] [blame] | 302 | * 5: POWER MANAGEMENT | 
| David S. Miller | 2b1e597 | 2006-06-29 15:07:37 -0700 | [diff] [blame] | 303 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 |  | 
| Grant Likely | 1636f8a | 2010-06-18 11:09:58 -0600 | [diff] [blame] | 305 | if (op->archdata.num_irqs < 6) | 
| David S. Miller | 2b1e597 | 2006-06-29 15:07:37 -0700 | [diff] [blame] | 306 | return; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 |  | 
| David S. Miller | af80318 | 2007-05-08 17:23:31 -0700 | [diff] [blame] | 308 | /* We really mean to ignore the return result here.  Two | 
|  | 309 | * PCI controller share the same interrupt numbers and | 
| David S. Miller | a0381a9 | 2009-01-02 19:12:46 -0800 | [diff] [blame] | 310 | * drive the same front-end hardware. | 
| David S. Miller | af80318 | 2007-05-08 17:23:31 -0700 | [diff] [blame] | 311 | */ | 
| Grant Likely | 1636f8a | 2010-06-18 11:09:58 -0600 | [diff] [blame] | 312 | err = request_irq(op->archdata.irqs[1], psycho_ue_intr, IRQF_SHARED, | 
| David S. Miller | af80318 | 2007-05-08 17:23:31 -0700 | [diff] [blame] | 313 | "PSYCHO_UE", pbm); | 
| Grant Likely | 1636f8a | 2010-06-18 11:09:58 -0600 | [diff] [blame] | 314 | err = request_irq(op->archdata.irqs[2], psycho_ce_intr, IRQF_SHARED, | 
| David S. Miller | af80318 | 2007-05-08 17:23:31 -0700 | [diff] [blame] | 315 | "PSYCHO_CE", pbm); | 
|  | 316 |  | 
|  | 317 | /* This one, however, ought not to fail.  We can just warn | 
|  | 318 | * about it since the system can still operate properly even | 
|  | 319 | * if this fails. | 
|  | 320 | */ | 
| Grant Likely | 1636f8a | 2010-06-18 11:09:58 -0600 | [diff] [blame] | 321 | err = request_irq(op->archdata.irqs[0], psycho_pcierr_intr, IRQF_SHARED, | 
| David S. Miller | af80318 | 2007-05-08 17:23:31 -0700 | [diff] [blame] | 322 | "PSYCHO_PCIERR", pbm); | 
|  | 323 | if (err) | 
|  | 324 | printk(KERN_WARNING "%s: Could not register PCIERR, " | 
|  | 325 | "err=%d\n", pbm->name, err); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 |  | 
|  | 327 | /* Enable UE and CE interrupts for controller. */ | 
| David S. Miller | 87395fc | 2008-09-10 04:13:10 -0700 | [diff] [blame] | 328 | upa_writeq((PSYCHO_ECCCTRL_EE | | 
|  | 329 | PSYCHO_ECCCTRL_UE | | 
|  | 330 | PSYCHO_ECCCTRL_CE), base + PSYCHO_ECC_CTRL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 |  | 
|  | 332 | /* Enable PCI Error interrupts and clear error | 
|  | 333 | * bits for each PBM. | 
|  | 334 | */ | 
| David S. Miller | 87395fc | 2008-09-10 04:13:10 -0700 | [diff] [blame] | 335 | tmp = upa_readq(base + PSYCHO_PCIA_CTRL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | tmp |= (PSYCHO_PCICTRL_SERR | | 
|  | 337 | PSYCHO_PCICTRL_SBH_ERR | | 
|  | 338 | PSYCHO_PCICTRL_EEN); | 
|  | 339 | tmp &= ~(PSYCHO_PCICTRL_SBH_INT); | 
| David S. Miller | 87395fc | 2008-09-10 04:13:10 -0700 | [diff] [blame] | 340 | upa_writeq(tmp, base + PSYCHO_PCIA_CTRL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 |  | 
| David S. Miller | 87395fc | 2008-09-10 04:13:10 -0700 | [diff] [blame] | 342 | tmp = upa_readq(base + PSYCHO_PCIB_CTRL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | tmp |= (PSYCHO_PCICTRL_SERR | | 
|  | 344 | PSYCHO_PCICTRL_SBH_ERR | | 
|  | 345 | PSYCHO_PCICTRL_EEN); | 
|  | 346 | tmp &= ~(PSYCHO_PCICTRL_SBH_INT); | 
| David S. Miller | 87395fc | 2008-09-10 04:13:10 -0700 | [diff] [blame] | 347 | upa_writeq(tmp, base + PSYCHO_PCIB_CTRL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | } | 
|  | 349 |  | 
|  | 350 | /* PSYCHO boot time probing and initialization. */ | 
| David S. Miller | 085ae41 | 2005-08-08 13:19:08 -0700 | [diff] [blame] | 351 | static void pbm_config_busmastering(struct pci_pbm_info *pbm) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | { | 
|  | 353 | u8 *addr; | 
|  | 354 |  | 
|  | 355 | /* Set cache-line size to 64 bytes, this is actually | 
|  | 356 | * a nop but I do it for completeness. | 
|  | 357 | */ | 
|  | 358 | addr = psycho_pci_config_mkaddr(pbm, pbm->pci_first_busno, | 
|  | 359 | 0, PCI_CACHE_LINE_SIZE); | 
|  | 360 | pci_config_write8(addr, 64 / sizeof(u32)); | 
|  | 361 |  | 
|  | 362 | /* Set PBM latency timer to 64 PCI clocks. */ | 
|  | 363 | addr = psycho_pci_config_mkaddr(pbm, pbm->pci_first_busno, | 
|  | 364 | 0, PCI_LATENCY_TIMER); | 
|  | 365 | pci_config_write8(addr, 64); | 
|  | 366 | } | 
|  | 367 |  | 
| David S. Miller | 9a2ed5c | 2009-04-07 01:03:58 -0700 | [diff] [blame] | 368 | static void __devinit psycho_scan_bus(struct pci_pbm_info *pbm, | 
|  | 369 | struct device *parent) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | { | 
| David S. Miller | 34768bc | 2007-05-07 23:06:27 -0700 | [diff] [blame] | 371 | pbm_config_busmastering(pbm); | 
|  | 372 | pbm->is_66mhz_capable = 0; | 
| David S. Miller | e822358a | 2008-09-01 18:32:22 -0700 | [diff] [blame] | 373 | pbm->pci_bus = pci_scan_one_pbm(pbm, parent); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 |  | 
|  | 375 | /* After the PCI bus scan is complete, we can register | 
|  | 376 | * the error interrupt handlers. | 
|  | 377 | */ | 
| David S. Miller | 34768bc | 2007-05-07 23:06:27 -0700 | [diff] [blame] | 378 | psycho_register_error_handlers(pbm); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | } | 
|  | 380 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | #define PSYCHO_IRQ_RETRY	0x1a00UL | 
|  | 382 | #define PSYCHO_PCIA_DIAG	0x2020UL | 
|  | 383 | #define PSYCHO_PCIB_DIAG	0x4020UL | 
|  | 384 | #define  PSYCHO_PCIDIAG_RESV	 0xffffffffffffff80UL /* Reserved                     */ | 
|  | 385 | #define  PSYCHO_PCIDIAG_DRETRY	 0x0000000000000040UL /* Disable retry limit          */ | 
|  | 386 | #define  PSYCHO_PCIDIAG_DISYNC	 0x0000000000000020UL /* Disable DMA wr / irq sync    */ | 
|  | 387 | #define  PSYCHO_PCIDIAG_DDWSYNC	 0x0000000000000010UL /* Disable DMA wr / PIO rd sync */ | 
|  | 388 | #define  PSYCHO_PCIDIAG_IDDPAR	 0x0000000000000008UL /* Invert DMA data parity       */ | 
|  | 389 | #define  PSYCHO_PCIDIAG_IPDPAR	 0x0000000000000004UL /* Invert PIO data parity       */ | 
|  | 390 | #define  PSYCHO_PCIDIAG_IPAPAR	 0x0000000000000002UL /* Invert PIO address parity    */ | 
|  | 391 | #define  PSYCHO_PCIDIAG_LPBACK	 0x0000000000000001UL /* Enable loopback mode         */ | 
|  | 392 |  | 
| David S. Miller | 28113a9 | 2007-05-08 00:19:02 -0700 | [diff] [blame] | 393 | static void psycho_controller_hwinit(struct pci_pbm_info *pbm) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | { | 
|  | 395 | u64 tmp; | 
|  | 396 |  | 
| David S. Miller | 87395fc | 2008-09-10 04:13:10 -0700 | [diff] [blame] | 397 | upa_writeq(5, pbm->controller_regs + PSYCHO_IRQ_RETRY); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 |  | 
|  | 399 | /* Enable arbiter for all PCI slots. */ | 
| David S. Miller | 87395fc | 2008-09-10 04:13:10 -0700 | [diff] [blame] | 400 | tmp = upa_readq(pbm->controller_regs + PSYCHO_PCIA_CTRL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | tmp |= PSYCHO_PCICTRL_AEN; | 
| David S. Miller | 87395fc | 2008-09-10 04:13:10 -0700 | [diff] [blame] | 402 | upa_writeq(tmp, pbm->controller_regs + PSYCHO_PCIA_CTRL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 |  | 
| David S. Miller | 87395fc | 2008-09-10 04:13:10 -0700 | [diff] [blame] | 404 | tmp = upa_readq(pbm->controller_regs + PSYCHO_PCIB_CTRL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | tmp |= PSYCHO_PCICTRL_AEN; | 
| David S. Miller | 87395fc | 2008-09-10 04:13:10 -0700 | [diff] [blame] | 406 | upa_writeq(tmp, pbm->controller_regs + PSYCHO_PCIB_CTRL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 |  | 
|  | 408 | /* Disable DMA write / PIO read synchronization on | 
|  | 409 | * both PCI bus segments. | 
|  | 410 | * [ U2P Erratum 1243770, STP2223BGA data sheet ] | 
|  | 411 | */ | 
| David S. Miller | 87395fc | 2008-09-10 04:13:10 -0700 | [diff] [blame] | 412 | tmp = upa_readq(pbm->controller_regs + PSYCHO_PCIA_DIAG); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | tmp |= PSYCHO_PCIDIAG_DDWSYNC; | 
| David S. Miller | 87395fc | 2008-09-10 04:13:10 -0700 | [diff] [blame] | 414 | upa_writeq(tmp, pbm->controller_regs + PSYCHO_PCIA_DIAG); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 |  | 
| David S. Miller | 87395fc | 2008-09-10 04:13:10 -0700 | [diff] [blame] | 416 | tmp = upa_readq(pbm->controller_regs + PSYCHO_PCIB_DIAG); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | tmp |= PSYCHO_PCIDIAG_DDWSYNC; | 
| David S. Miller | 87395fc | 2008-09-10 04:13:10 -0700 | [diff] [blame] | 418 | upa_writeq(tmp, pbm->controller_regs + PSYCHO_PCIB_DIAG); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | } | 
|  | 420 |  | 
| David S. Miller | 28113a9 | 2007-05-08 00:19:02 -0700 | [diff] [blame] | 421 | static void psycho_pbm_strbuf_init(struct pci_pbm_info *pbm, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | int is_pbm_a) | 
|  | 423 | { | 
|  | 424 | unsigned long base = pbm->controller_regs; | 
|  | 425 | u64 control; | 
|  | 426 |  | 
|  | 427 | if (is_pbm_a) { | 
|  | 428 | pbm->stc.strbuf_control  = base + PSYCHO_STRBUF_CONTROL_A; | 
|  | 429 | pbm->stc.strbuf_pflush   = base + PSYCHO_STRBUF_FLUSH_A; | 
|  | 430 | pbm->stc.strbuf_fsync    = base + PSYCHO_STRBUF_FSYNC_A; | 
| David S. Miller | d3ae4b5 | 2008-09-09 23:54:02 -0700 | [diff] [blame] | 431 | pbm->stc.strbuf_err_stat = base + PSYCHO_STC_ERR_A; | 
|  | 432 | pbm->stc.strbuf_tag_diag = base + PSYCHO_STC_TAG_A; | 
|  | 433 | pbm->stc.strbuf_line_diag= base + PSYCHO_STC_LINE_A; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | } else { | 
|  | 435 | pbm->stc.strbuf_control  = base + PSYCHO_STRBUF_CONTROL_B; | 
|  | 436 | pbm->stc.strbuf_pflush   = base + PSYCHO_STRBUF_FLUSH_B; | 
|  | 437 | pbm->stc.strbuf_fsync    = base + PSYCHO_STRBUF_FSYNC_B; | 
| David S. Miller | d3ae4b5 | 2008-09-09 23:54:02 -0700 | [diff] [blame] | 438 | pbm->stc.strbuf_err_stat = base + PSYCHO_STC_ERR_B; | 
|  | 439 | pbm->stc.strbuf_tag_diag = base + PSYCHO_STC_TAG_B; | 
|  | 440 | pbm->stc.strbuf_line_diag= base + PSYCHO_STC_LINE_B; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | } | 
|  | 442 | /* PSYCHO's streaming buffer lacks ctx flushing. */ | 
|  | 443 | pbm->stc.strbuf_ctxflush      = 0; | 
|  | 444 | pbm->stc.strbuf_ctxmatch_base = 0; | 
|  | 445 |  | 
|  | 446 | pbm->stc.strbuf_flushflag = (volatile unsigned long *) | 
|  | 447 | ((((unsigned long)&pbm->stc.__flushflag_buf[0]) | 
|  | 448 | + 63UL) | 
|  | 449 | & ~63UL); | 
|  | 450 | pbm->stc.strbuf_flushflag_pa = (unsigned long) | 
|  | 451 | __pa(pbm->stc.strbuf_flushflag); | 
|  | 452 |  | 
|  | 453 | /* Enable the streaming buffer.  We have to be careful | 
|  | 454 | * just in case OBP left it with LRU locking enabled. | 
|  | 455 | * | 
|  | 456 | * It is possible to control if PBM will be rerun on | 
|  | 457 | * line misses.  Currently I just retain whatever setting | 
|  | 458 | * OBP left us with.  All checks so far show it having | 
|  | 459 | * a value of zero. | 
|  | 460 | */ | 
|  | 461 | #undef PSYCHO_STRBUF_RERUN_ENABLE | 
|  | 462 | #undef PSYCHO_STRBUF_RERUN_DISABLE | 
| David S. Miller | 87395fc | 2008-09-10 04:13:10 -0700 | [diff] [blame] | 463 | control = upa_readq(pbm->stc.strbuf_control); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | control |= PSYCHO_STRBUF_CTRL_ENAB; | 
|  | 465 | control &= ~(PSYCHO_STRBUF_CTRL_LENAB | PSYCHO_STRBUF_CTRL_LPTR); | 
|  | 466 | #ifdef PSYCHO_STRBUF_RERUN_ENABLE | 
|  | 467 | control &= ~(PSYCHO_STRBUF_CTRL_RRDIS); | 
|  | 468 | #else | 
|  | 469 | #ifdef PSYCHO_STRBUF_RERUN_DISABLE | 
|  | 470 | control |= PSYCHO_STRBUF_CTRL_RRDIS; | 
|  | 471 | #endif | 
|  | 472 | #endif | 
| David S. Miller | 87395fc | 2008-09-10 04:13:10 -0700 | [diff] [blame] | 473 | upa_writeq(control, pbm->stc.strbuf_control); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 |  | 
|  | 475 | pbm->stc.strbuf_enabled = 1; | 
|  | 476 | } | 
|  | 477 |  | 
|  | 478 | #define PSYCHO_IOSPACE_A	0x002000000UL | 
|  | 479 | #define PSYCHO_IOSPACE_B	0x002010000UL | 
|  | 480 | #define PSYCHO_IOSPACE_SIZE	0x00000ffffUL | 
|  | 481 | #define PSYCHO_MEMSPACE_A	0x100000000UL | 
|  | 482 | #define PSYCHO_MEMSPACE_B	0x180000000UL | 
|  | 483 | #define PSYCHO_MEMSPACE_SIZE	0x07fffffffUL | 
|  | 484 |  | 
| David S. Miller | 9a2ed5c | 2009-04-07 01:03:58 -0700 | [diff] [blame] | 485 | static void __devinit psycho_pbm_init(struct pci_pbm_info *pbm, | 
| Grant Likely | cd4cd73 | 2010-07-22 16:04:30 -0600 | [diff] [blame] | 486 | struct platform_device *op, int is_pbm_a) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | { | 
| David S. Miller | 1c03a55 | 2008-09-10 03:15:56 -0700 | [diff] [blame] | 488 | psycho_pbm_init_common(pbm, op, "PSYCHO", PBM_CHIP_TYPE_PSYCHO); | 
| David S. Miller | 28113a9 | 2007-05-08 00:19:02 -0700 | [diff] [blame] | 489 | psycho_pbm_strbuf_init(pbm, is_pbm_a); | 
| David S. Miller | e822358a | 2008-09-01 18:32:22 -0700 | [diff] [blame] | 490 | psycho_scan_bus(pbm, &op->dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | } | 
|  | 492 |  | 
| Linus Torvalds | 33b07db | 2008-12-01 07:55:14 -0800 | [diff] [blame] | 493 | static struct pci_pbm_info * __devinit psycho_find_sibling(u32 upa_portid) | 
| David S. Miller | d3ae4b5 | 2008-09-09 23:54:02 -0700 | [diff] [blame] | 494 | { | 
|  | 495 | struct pci_pbm_info *pbm; | 
|  | 496 |  | 
|  | 497 | for (pbm = pci_pbm_root; pbm; pbm = pbm->next) { | 
|  | 498 | if (pbm->portid == upa_portid) | 
|  | 499 | return pbm; | 
|  | 500 | } | 
|  | 501 | return NULL; | 
|  | 502 | } | 
|  | 503 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | #define PSYCHO_CONFIGSPACE	0x001000000UL | 
|  | 505 |  | 
| Grant Likely | 4ebb24f | 2011-02-22 20:01:33 -0700 | [diff] [blame] | 506 | static int __devinit psycho_probe(struct platform_device *op) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | { | 
| David S. Miller | b20bfe4 | 2008-08-30 03:13:20 -0700 | [diff] [blame] | 508 | const struct linux_prom64_registers *pr_regs; | 
| Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 509 | struct device_node *dp = op->dev.of_node; | 
| David S. Miller | 34768bc | 2007-05-07 23:06:27 -0700 | [diff] [blame] | 510 | struct pci_pbm_info *pbm; | 
| David S. Miller | 16ce82d | 2007-04-26 21:08:21 -0700 | [diff] [blame] | 511 | struct iommu *iommu; | 
| David S. Miller | b20bfe4 | 2008-08-30 03:13:20 -0700 | [diff] [blame] | 512 | int is_pbm_a, err; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | u32 upa_portid; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 |  | 
| David S. Miller | 0f73d1b | 2008-09-01 20:18:04 -0700 | [diff] [blame] | 515 | upa_portid = of_getintprop_default(dp, "upa-portid", 0xff); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 |  | 
| David S. Miller | b20bfe4 | 2008-08-30 03:13:20 -0700 | [diff] [blame] | 517 | err = -ENOMEM; | 
| David S. Miller | d3ae4b5 | 2008-09-09 23:54:02 -0700 | [diff] [blame] | 518 | pbm = kzalloc(sizeof(*pbm), GFP_KERNEL); | 
|  | 519 | if (!pbm) { | 
|  | 520 | printk(KERN_ERR PFX "Cannot allocate pci_pbm_info.\n"); | 
| David S. Miller | d7472c3 | 2008-08-31 01:33:52 -0700 | [diff] [blame] | 521 | goto out_err; | 
| David S. Miller | b20bfe4 | 2008-08-30 03:13:20 -0700 | [diff] [blame] | 522 | } | 
|  | 523 |  | 
| David S. Miller | d3ae4b5 | 2008-09-09 23:54:02 -0700 | [diff] [blame] | 524 | pbm->sibling = psycho_find_sibling(upa_portid); | 
|  | 525 | if (pbm->sibling) { | 
|  | 526 | iommu = pbm->sibling->iommu; | 
|  | 527 | } else { | 
|  | 528 | iommu = kzalloc(sizeof(struct iommu), GFP_KERNEL); | 
|  | 529 | if (!iommu) { | 
|  | 530 | printk(KERN_ERR PFX "Cannot allocate PBM iommu.\n"); | 
|  | 531 | goto out_free_controller; | 
|  | 532 | } | 
| David S. Miller | b20bfe4 | 2008-08-30 03:13:20 -0700 | [diff] [blame] | 533 | } | 
| David S. Miller | ad7ad57 | 2007-07-27 22:39:14 -0700 | [diff] [blame] | 534 |  | 
| David S. Miller | d3ae4b5 | 2008-09-09 23:54:02 -0700 | [diff] [blame] | 535 | pbm->iommu = iommu; | 
|  | 536 | pbm->portid = upa_portid; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 |  | 
| David S. Miller | b20bfe4 | 2008-08-30 03:13:20 -0700 | [diff] [blame] | 538 | pr_regs = of_get_property(dp, "reg", NULL); | 
|  | 539 | err = -ENODEV; | 
|  | 540 | if (!pr_regs) { | 
|  | 541 | printk(KERN_ERR PFX "No reg property.\n"); | 
| David S. Miller | d7472c3 | 2008-08-31 01:33:52 -0700 | [diff] [blame] | 542 | goto out_free_iommu; | 
| David S. Miller | b20bfe4 | 2008-08-30 03:13:20 -0700 | [diff] [blame] | 543 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | is_pbm_a = ((pr_regs[0].phys_addr & 0x6000) == 0x2000); | 
| David S. Miller | ad7ad57 | 2007-07-27 22:39:14 -0700 | [diff] [blame] | 546 |  | 
| David S. Miller | d3ae4b5 | 2008-09-09 23:54:02 -0700 | [diff] [blame] | 547 | pbm->controller_regs = pr_regs[2].phys_addr; | 
|  | 548 | pbm->config_space = (pr_regs[2].phys_addr + PSYCHO_CONFIGSPACE); | 
|  | 549 |  | 
|  | 550 | if (is_pbm_a) { | 
|  | 551 | pbm->pci_afsr = pbm->controller_regs + PSYCHO_PCI_AFSR_A; | 
|  | 552 | pbm->pci_afar = pbm->controller_regs + PSYCHO_PCI_AFAR_A; | 
|  | 553 | pbm->pci_csr  = pbm->controller_regs + PSYCHO_PCIA_CTRL; | 
|  | 554 | } else { | 
|  | 555 | pbm->pci_afsr = pbm->controller_regs + PSYCHO_PCI_AFSR_B; | 
|  | 556 | pbm->pci_afar = pbm->controller_regs + PSYCHO_PCI_AFAR_B; | 
|  | 557 | pbm->pci_csr  = pbm->controller_regs + PSYCHO_PCIB_CTRL; | 
|  | 558 | } | 
|  | 559 |  | 
|  | 560 | psycho_controller_hwinit(pbm); | 
|  | 561 | if (!pbm->sibling) { | 
| David S. Miller | a21cff3 | 2008-09-10 03:07:03 -0700 | [diff] [blame] | 562 | err = psycho_iommu_init(pbm, 128, 0xc0000000, | 
|  | 563 | 0xffffffff, PSYCHO_CONTROL); | 
| David S. Miller | d3ae4b5 | 2008-09-09 23:54:02 -0700 | [diff] [blame] | 564 | if (err) | 
|  | 565 | goto out_free_iommu; | 
| David S. Miller | a21cff3 | 2008-09-10 03:07:03 -0700 | [diff] [blame] | 566 |  | 
|  | 567 | /* If necessary, hook us up for starfire IRQ translations. */ | 
|  | 568 | if (this_is_starfire) | 
|  | 569 | starfire_hookup(pbm->portid); | 
| David S. Miller | d3ae4b5 | 2008-09-09 23:54:02 -0700 | [diff] [blame] | 570 | } | 
|  | 571 |  | 
|  | 572 | psycho_pbm_init(pbm, op, is_pbm_a); | 
|  | 573 |  | 
| David S. Miller | 1c03a55 | 2008-09-10 03:15:56 -0700 | [diff] [blame] | 574 | pbm->next = pci_pbm_root; | 
|  | 575 | pci_pbm_root = pbm; | 
|  | 576 |  | 
| David S. Miller | d3ae4b5 | 2008-09-09 23:54:02 -0700 | [diff] [blame] | 577 | if (pbm->sibling) | 
|  | 578 | pbm->sibling->sibling = pbm; | 
|  | 579 |  | 
|  | 580 | dev_set_drvdata(&op->dev, pbm); | 
| David S. Miller | b20bfe4 | 2008-08-30 03:13:20 -0700 | [diff] [blame] | 581 |  | 
|  | 582 | return 0; | 
|  | 583 |  | 
| David S. Miller | d7472c3 | 2008-08-31 01:33:52 -0700 | [diff] [blame] | 584 | out_free_iommu: | 
| David S. Miller | d3ae4b5 | 2008-09-09 23:54:02 -0700 | [diff] [blame] | 585 | if (!pbm->sibling) | 
|  | 586 | kfree(pbm->iommu); | 
| David S. Miller | d7472c3 | 2008-08-31 01:33:52 -0700 | [diff] [blame] | 587 |  | 
|  | 588 | out_free_controller: | 
| David S. Miller | d3ae4b5 | 2008-09-09 23:54:02 -0700 | [diff] [blame] | 589 | kfree(pbm); | 
| David S. Miller | d7472c3 | 2008-08-31 01:33:52 -0700 | [diff] [blame] | 590 |  | 
|  | 591 | out_err: | 
| David S. Miller | b20bfe4 | 2008-08-30 03:13:20 -0700 | [diff] [blame] | 592 | return err; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | } | 
| David S. Miller | b20bfe4 | 2008-08-30 03:13:20 -0700 | [diff] [blame] | 594 |  | 
| David S. Miller | 3628aa0 | 2011-03-30 17:37:56 -0700 | [diff] [blame] | 595 | static const struct of_device_id psycho_match[] = { | 
| David S. Miller | b20bfe4 | 2008-08-30 03:13:20 -0700 | [diff] [blame] | 596 | { | 
|  | 597 | .name = "pci", | 
|  | 598 | .compatible = "pci108e,8000", | 
|  | 599 | }, | 
|  | 600 | {}, | 
|  | 601 | }; | 
|  | 602 |  | 
| Grant Likely | 4ebb24f | 2011-02-22 20:01:33 -0700 | [diff] [blame] | 603 | static struct platform_driver psycho_driver = { | 
| Grant Likely | 4018294 | 2010-04-13 16:13:02 -0700 | [diff] [blame] | 604 | .driver = { | 
|  | 605 | .name = DRIVER_NAME, | 
|  | 606 | .owner = THIS_MODULE, | 
|  | 607 | .of_match_table = psycho_match, | 
|  | 608 | }, | 
| David S. Miller | b20bfe4 | 2008-08-30 03:13:20 -0700 | [diff] [blame] | 609 | .probe		= psycho_probe, | 
|  | 610 | }; | 
|  | 611 |  | 
|  | 612 | static int __init psycho_init(void) | 
|  | 613 | { | 
| Grant Likely | 4ebb24f | 2011-02-22 20:01:33 -0700 | [diff] [blame] | 614 | return platform_driver_register(&psycho_driver); | 
| David S. Miller | b20bfe4 | 2008-08-30 03:13:20 -0700 | [diff] [blame] | 615 | } | 
|  | 616 |  | 
|  | 617 | subsys_initcall(psycho_init); |