blob: f8089aa84f6450f0d466f6a3785d91f786d1f385 [file] [log] [blame]
David S. Miller16ce82d2007-04-26 21:08:21 -07001/* pci_sabre.c: Sabre specific PCI controller support.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
David S. Miller16ce82d2007-04-26 21:08:21 -07003 * Copyright (C) 1997, 1998, 1999, 2007 David S. Miller (davem@davemloft.net)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * 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 Rothwell764f2572008-08-07 15:33:36 -070014#include <linux/of_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
16#include <asm/apb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <asm/iommu.h>
18#include <asm/irq.h>
David S. Millere87dc352006-06-21 18:18:47 -070019#include <asm/prom.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
21#include "pci_impl.h"
22#include "iommu_common.h"
David S. Millera21cff32008-09-10 03:07:03 -070023#include "psycho_common.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
David S. Milleredbe8052008-08-30 03:14:01 -070025#define DRIVER_NAME "sabre"
26#define PFX DRIVER_NAME ": "
27
Linus Torvalds1da177e2005-04-16 15:20:36 -070028/* All SABRE registers are 64-bits. The following accessor
29 * routines are how they are accessed. The REG parameter
30 * is a physical address.
31 */
32#define sabre_read(__reg) \
33({ u64 __ret; \
34 __asm__ __volatile__("ldxa [%1] %2, %0" \
35 : "=r" (__ret) \
36 : "r" (__reg), "i" (ASI_PHYS_BYPASS_EC_E) \
37 : "memory"); \
38 __ret; \
39})
40#define sabre_write(__reg, __val) \
41 __asm__ __volatile__("stxa %0, [%1] %2" \
42 : /* no outputs */ \
43 : "r" (__val), "r" (__reg), \
44 "i" (ASI_PHYS_BYPASS_EC_E) \
45 : "memory")
46
47/* SABRE PCI controller register offsets and definitions. */
48#define SABRE_UE_AFSR 0x0030UL
49#define SABRE_UEAFSR_PDRD 0x4000000000000000UL /* Primary PCI DMA Read */
50#define SABRE_UEAFSR_PDWR 0x2000000000000000UL /* Primary PCI DMA Write */
51#define SABRE_UEAFSR_SDRD 0x0800000000000000UL /* Secondary PCI DMA Read */
52#define SABRE_UEAFSR_SDWR 0x0400000000000000UL /* Secondary PCI DMA Write */
53#define SABRE_UEAFSR_SDTE 0x0200000000000000UL /* Secondary DMA Translation Error */
54#define SABRE_UEAFSR_PDTE 0x0100000000000000UL /* Primary DMA Translation Error */
55#define SABRE_UEAFSR_BMSK 0x0000ffff00000000UL /* Bytemask */
56#define SABRE_UEAFSR_OFF 0x00000000e0000000UL /* Offset (AFAR bits [5:3] */
57#define SABRE_UEAFSR_BLK 0x0000000000800000UL /* Was block operation */
58#define SABRE_UECE_AFAR 0x0038UL
59#define SABRE_CE_AFSR 0x0040UL
60#define SABRE_CEAFSR_PDRD 0x4000000000000000UL /* Primary PCI DMA Read */
61#define SABRE_CEAFSR_PDWR 0x2000000000000000UL /* Primary PCI DMA Write */
62#define SABRE_CEAFSR_SDRD 0x0800000000000000UL /* Secondary PCI DMA Read */
63#define SABRE_CEAFSR_SDWR 0x0400000000000000UL /* Secondary PCI DMA Write */
64#define SABRE_CEAFSR_ESYND 0x00ff000000000000UL /* ECC Syndrome */
65#define SABRE_CEAFSR_BMSK 0x0000ffff00000000UL /* Bytemask */
66#define SABRE_CEAFSR_OFF 0x00000000e0000000UL /* Offset */
67#define SABRE_CEAFSR_BLK 0x0000000000800000UL /* Was block operation */
68#define SABRE_UECE_AFAR_ALIAS 0x0048UL /* Aliases to 0x0038 */
69#define SABRE_IOMMU_CONTROL 0x0200UL
70#define SABRE_IOMMUCTRL_ERRSTS 0x0000000006000000UL /* Error status bits */
71#define SABRE_IOMMUCTRL_ERR 0x0000000001000000UL /* Error present in IOTLB */
72#define SABRE_IOMMUCTRL_LCKEN 0x0000000000800000UL /* IOTLB lock enable */
73#define SABRE_IOMMUCTRL_LCKPTR 0x0000000000780000UL /* IOTLB lock pointer */
74#define SABRE_IOMMUCTRL_TSBSZ 0x0000000000070000UL /* TSB Size */
75#define SABRE_IOMMU_TSBSZ_1K 0x0000000000000000
76#define SABRE_IOMMU_TSBSZ_2K 0x0000000000010000
77#define SABRE_IOMMU_TSBSZ_4K 0x0000000000020000
78#define SABRE_IOMMU_TSBSZ_8K 0x0000000000030000
79#define SABRE_IOMMU_TSBSZ_16K 0x0000000000040000
80#define SABRE_IOMMU_TSBSZ_32K 0x0000000000050000
81#define SABRE_IOMMU_TSBSZ_64K 0x0000000000060000
82#define SABRE_IOMMU_TSBSZ_128K 0x0000000000070000
83#define SABRE_IOMMUCTRL_TBWSZ 0x0000000000000004UL /* TSB assumed page size */
84#define SABRE_IOMMUCTRL_DENAB 0x0000000000000002UL /* Diagnostic Mode Enable */
85#define SABRE_IOMMUCTRL_ENAB 0x0000000000000001UL /* IOMMU Enable */
86#define SABRE_IOMMU_TSBBASE 0x0208UL
87#define SABRE_IOMMU_FLUSH 0x0210UL
88#define SABRE_IMAP_A_SLOT0 0x0c00UL
89#define SABRE_IMAP_B_SLOT0 0x0c20UL
90#define SABRE_IMAP_SCSI 0x1000UL
91#define SABRE_IMAP_ETH 0x1008UL
92#define SABRE_IMAP_BPP 0x1010UL
93#define SABRE_IMAP_AU_REC 0x1018UL
94#define SABRE_IMAP_AU_PLAY 0x1020UL
95#define SABRE_IMAP_PFAIL 0x1028UL
96#define SABRE_IMAP_KMS 0x1030UL
97#define SABRE_IMAP_FLPY 0x1038UL
98#define SABRE_IMAP_SHW 0x1040UL
99#define SABRE_IMAP_KBD 0x1048UL
100#define SABRE_IMAP_MS 0x1050UL
101#define SABRE_IMAP_SER 0x1058UL
102#define SABRE_IMAP_UE 0x1070UL
103#define SABRE_IMAP_CE 0x1078UL
104#define SABRE_IMAP_PCIERR 0x1080UL
105#define SABRE_IMAP_GFX 0x1098UL
106#define SABRE_IMAP_EUPA 0x10a0UL
107#define SABRE_ICLR_A_SLOT0 0x1400UL
108#define SABRE_ICLR_B_SLOT0 0x1480UL
109#define SABRE_ICLR_SCSI 0x1800UL
110#define SABRE_ICLR_ETH 0x1808UL
111#define SABRE_ICLR_BPP 0x1810UL
112#define SABRE_ICLR_AU_REC 0x1818UL
113#define SABRE_ICLR_AU_PLAY 0x1820UL
114#define SABRE_ICLR_PFAIL 0x1828UL
115#define SABRE_ICLR_KMS 0x1830UL
116#define SABRE_ICLR_FLPY 0x1838UL
117#define SABRE_ICLR_SHW 0x1840UL
118#define SABRE_ICLR_KBD 0x1848UL
119#define SABRE_ICLR_MS 0x1850UL
120#define SABRE_ICLR_SER 0x1858UL
121#define SABRE_ICLR_UE 0x1870UL
122#define SABRE_ICLR_CE 0x1878UL
123#define SABRE_ICLR_PCIERR 0x1880UL
124#define SABRE_WRSYNC 0x1c20UL
125#define SABRE_PCICTRL 0x2000UL
126#define SABRE_PCICTRL_MRLEN 0x0000001000000000UL /* Use MemoryReadLine for block loads/stores */
127#define SABRE_PCICTRL_SERR 0x0000000400000000UL /* Set when SERR asserted on PCI bus */
128#define SABRE_PCICTRL_ARBPARK 0x0000000000200000UL /* Bus Parking 0=Ultra-IIi 1=prev-bus-owner */
129#define SABRE_PCICTRL_CPUPRIO 0x0000000000100000UL /* Ultra-IIi granted every other bus cycle */
130#define SABRE_PCICTRL_ARBPRIO 0x00000000000f0000UL /* Slot which is granted every other bus cycle */
131#define SABRE_PCICTRL_ERREN 0x0000000000000100UL /* PCI Error Interrupt Enable */
132#define SABRE_PCICTRL_RTRYWE 0x0000000000000080UL /* DMA Flow Control 0=wait-if-possible 1=retry */
133#define SABRE_PCICTRL_AEN 0x000000000000000fUL /* Slot PCI arbitration enables */
134#define SABRE_PIOAFSR 0x2010UL
135#define SABRE_PIOAFSR_PMA 0x8000000000000000UL /* Primary Master Abort */
136#define SABRE_PIOAFSR_PTA 0x4000000000000000UL /* Primary Target Abort */
137#define SABRE_PIOAFSR_PRTRY 0x2000000000000000UL /* Primary Excessive Retries */
138#define SABRE_PIOAFSR_PPERR 0x1000000000000000UL /* Primary Parity Error */
139#define SABRE_PIOAFSR_SMA 0x0800000000000000UL /* Secondary Master Abort */
140#define SABRE_PIOAFSR_STA 0x0400000000000000UL /* Secondary Target Abort */
141#define SABRE_PIOAFSR_SRTRY 0x0200000000000000UL /* Secondary Excessive Retries */
142#define SABRE_PIOAFSR_SPERR 0x0100000000000000UL /* Secondary Parity Error */
143#define SABRE_PIOAFSR_BMSK 0x0000ffff00000000UL /* Byte Mask */
144#define SABRE_PIOAFSR_BLK 0x0000000080000000UL /* Was Block Operation */
145#define SABRE_PIOAFAR 0x2018UL
146#define SABRE_PCIDIAG 0x2020UL
147#define SABRE_PCIDIAG_DRTRY 0x0000000000000040UL /* Disable PIO Retry Limit */
148#define SABRE_PCIDIAG_IPAPAR 0x0000000000000008UL /* Invert PIO Address Parity */
149#define SABRE_PCIDIAG_IPDPAR 0x0000000000000004UL /* Invert PIO Data Parity */
150#define SABRE_PCIDIAG_IDDPAR 0x0000000000000002UL /* Invert DMA Data Parity */
151#define SABRE_PCIDIAG_ELPBK 0x0000000000000001UL /* Loopback Enable - not supported */
152#define SABRE_PCITASR 0x2028UL
153#define SABRE_PCITASR_EF 0x0000000000000080UL /* Respond to 0xe0000000-0xffffffff */
154#define SABRE_PCITASR_CD 0x0000000000000040UL /* Respond to 0xc0000000-0xdfffffff */
155#define SABRE_PCITASR_AB 0x0000000000000020UL /* Respond to 0xa0000000-0xbfffffff */
156#define SABRE_PCITASR_89 0x0000000000000010UL /* Respond to 0x80000000-0x9fffffff */
157#define SABRE_PCITASR_67 0x0000000000000008UL /* Respond to 0x60000000-0x7fffffff */
158#define SABRE_PCITASR_45 0x0000000000000004UL /* Respond to 0x40000000-0x5fffffff */
159#define SABRE_PCITASR_23 0x0000000000000002UL /* Respond to 0x20000000-0x3fffffff */
160#define SABRE_PCITASR_01 0x0000000000000001UL /* Respond to 0x00000000-0x1fffffff */
161#define SABRE_PIOBUF_DIAG 0x5000UL
162#define SABRE_DMABUF_DIAGLO 0x5100UL
163#define SABRE_DMABUF_DIAGHI 0x51c0UL
164#define SABRE_IMAP_GFX_ALIAS 0x6000UL /* Aliases to 0x1098 */
165#define SABRE_IMAP_EUPA_ALIAS 0x8000UL /* Aliases to 0x10a0 */
166#define SABRE_IOMMU_VADIAG 0xa400UL
167#define SABRE_IOMMU_TCDIAG 0xa408UL
168#define SABRE_IOMMU_TAG 0xa580UL
169#define SABRE_IOMMUTAG_ERRSTS 0x0000000001800000UL /* Error status bits */
170#define SABRE_IOMMUTAG_ERR 0x0000000000400000UL /* Error present */
171#define SABRE_IOMMUTAG_WRITE 0x0000000000200000UL /* Page is writable */
172#define SABRE_IOMMUTAG_STREAM 0x0000000000100000UL /* Streamable bit - unused */
173#define SABRE_IOMMUTAG_SIZE 0x0000000000080000UL /* 0=8k 1=16k */
174#define SABRE_IOMMUTAG_VPN 0x000000000007ffffUL /* Virtual Page Number [31:13] */
175#define SABRE_IOMMU_DATA 0xa600UL
176#define SABRE_IOMMUDATA_VALID 0x0000000040000000UL /* Valid */
177#define SABRE_IOMMUDATA_USED 0x0000000020000000UL /* Used (for LRU algorithm) */
178#define SABRE_IOMMUDATA_CACHE 0x0000000010000000UL /* Cacheable */
179#define SABRE_IOMMUDATA_PPN 0x00000000001fffffUL /* Physical Page Number [33:13] */
180#define SABRE_PCI_IRQSTATE 0xa800UL
181#define SABRE_OBIO_IRQSTATE 0xa808UL
182#define SABRE_FFBCFG 0xf000UL
183#define SABRE_FFBCFG_SPRQS 0x000000000f000000 /* Slave P_RQST queue size */
184#define SABRE_FFBCFG_ONEREAD 0x0000000000004000 /* Slave supports one outstanding read */
185#define SABRE_MCCTRL0 0xf010UL
186#define SABRE_MCCTRL0_RENAB 0x0000000080000000 /* Refresh Enable */
187#define SABRE_MCCTRL0_EENAB 0x0000000010000000 /* Enable all ECC functions */
188#define SABRE_MCCTRL0_11BIT 0x0000000000001000 /* Enable 11-bit column addressing */
189#define SABRE_MCCTRL0_DPP 0x0000000000000f00 /* DIMM Pair Present Bits */
190#define SABRE_MCCTRL0_RINTVL 0x00000000000000ff /* Refresh Interval */
191#define SABRE_MCCTRL1 0xf018UL
192#define SABRE_MCCTRL1_AMDC 0x0000000038000000 /* Advance Memdata Clock */
193#define SABRE_MCCTRL1_ARDC 0x0000000007000000 /* Advance DRAM Read Data Clock */
194#define SABRE_MCCTRL1_CSR 0x0000000000e00000 /* CAS to RAS delay for CBR refresh */
195#define SABRE_MCCTRL1_CASRW 0x00000000001c0000 /* CAS length for read/write */
196#define SABRE_MCCTRL1_RCD 0x0000000000038000 /* RAS to CAS delay */
197#define SABRE_MCCTRL1_CP 0x0000000000007000 /* CAS Precharge */
198#define SABRE_MCCTRL1_RP 0x0000000000000e00 /* RAS Precharge */
199#define SABRE_MCCTRL1_RAS 0x00000000000001c0 /* Length of RAS for refresh */
200#define SABRE_MCCTRL1_CASRW2 0x0000000000000038 /* Must be same as CASRW */
201#define SABRE_MCCTRL1_RSC 0x0000000000000007 /* RAS after CAS hold time */
202#define SABRE_RESETCTRL 0xf020UL
203
204#define SABRE_CONFIGSPACE 0x001000000UL
205#define SABRE_IOSPACE 0x002000000UL
206#define SABRE_IOSPACE_SIZE 0x000ffffffUL
207#define SABRE_MEMSPACE 0x100000000UL
208#define SABRE_MEMSPACE_SIZE 0x07fffffffUL
209
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210static int hummingbird_p;
211static struct pci_bus *sabre_root_bus;
212
Al Viro6d24c8d2006-10-08 08:23:28 -0400213static irqreturn_t sabre_ue_intr(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214{
David S. Miller6c108f12007-05-07 23:49:01 -0700215 struct pci_pbm_info *pbm = dev_id;
216 unsigned long afsr_reg = pbm->controller_regs + SABRE_UE_AFSR;
217 unsigned long afar_reg = pbm->controller_regs + SABRE_UECE_AFAR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 unsigned long afsr, afar, error_bits;
219 int reported;
220
221 /* Latch uncorrectable error status. */
222 afar = sabre_read(afar_reg);
223 afsr = sabre_read(afsr_reg);
224
225 /* Clear the primary/secondary error status bits. */
226 error_bits = afsr &
227 (SABRE_UEAFSR_PDRD | SABRE_UEAFSR_PDWR |
228 SABRE_UEAFSR_SDRD | SABRE_UEAFSR_SDWR |
229 SABRE_UEAFSR_SDTE | SABRE_UEAFSR_PDTE);
230 if (!error_bits)
231 return IRQ_NONE;
232 sabre_write(afsr_reg, error_bits);
233
234 /* Log the error. */
David S. Miller6c108f12007-05-07 23:49:01 -0700235 printk("%s: Uncorrectable Error, primary error type[%s%s]\n",
236 pbm->name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 ((error_bits & SABRE_UEAFSR_PDRD) ?
238 "DMA Read" :
239 ((error_bits & SABRE_UEAFSR_PDWR) ?
240 "DMA Write" : "???")),
241 ((error_bits & SABRE_UEAFSR_PDTE) ?
242 ":Translation Error" : ""));
David S. Miller6c108f12007-05-07 23:49:01 -0700243 printk("%s: bytemask[%04lx] dword_offset[%lx] was_block(%d)\n",
244 pbm->name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 (afsr & SABRE_UEAFSR_BMSK) >> 32UL,
246 (afsr & SABRE_UEAFSR_OFF) >> 29UL,
247 ((afsr & SABRE_UEAFSR_BLK) ? 1 : 0));
David S. Miller6c108f12007-05-07 23:49:01 -0700248 printk("%s: UE AFAR [%016lx]\n", pbm->name, afar);
249 printk("%s: UE Secondary errors [", pbm->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 reported = 0;
251 if (afsr & SABRE_UEAFSR_SDRD) {
252 reported++;
253 printk("(DMA Read)");
254 }
255 if (afsr & SABRE_UEAFSR_SDWR) {
256 reported++;
257 printk("(DMA Write)");
258 }
259 if (afsr & SABRE_UEAFSR_SDTE) {
260 reported++;
261 printk("(Translation Error)");
262 }
263 if (!reported)
264 printk("(none)");
265 printk("]\n");
266
267 /* Interrogate IOMMU for error status. */
David S. Millere6e00372008-09-10 03:52:51 -0700268 psycho_check_iommu_error(pbm, afsr, afar, UE_ERR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
270 return IRQ_HANDLED;
271}
272
Al Viro6d24c8d2006-10-08 08:23:28 -0400273static irqreturn_t sabre_ce_intr(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274{
David S. Miller6c108f12007-05-07 23:49:01 -0700275 struct pci_pbm_info *pbm = dev_id;
276 unsigned long afsr_reg = pbm->controller_regs + SABRE_CE_AFSR;
277 unsigned long afar_reg = pbm->controller_regs + SABRE_UECE_AFAR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 unsigned long afsr, afar, error_bits;
279 int reported;
280
281 /* Latch error status. */
282 afar = sabre_read(afar_reg);
283 afsr = sabre_read(afsr_reg);
284
285 /* Clear primary/secondary error status bits. */
286 error_bits = afsr &
287 (SABRE_CEAFSR_PDRD | SABRE_CEAFSR_PDWR |
288 SABRE_CEAFSR_SDRD | SABRE_CEAFSR_SDWR);
289 if (!error_bits)
290 return IRQ_NONE;
291 sabre_write(afsr_reg, error_bits);
292
293 /* Log the error. */
David S. Miller6c108f12007-05-07 23:49:01 -0700294 printk("%s: Correctable Error, primary error type[%s]\n",
295 pbm->name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 ((error_bits & SABRE_CEAFSR_PDRD) ?
297 "DMA Read" :
298 ((error_bits & SABRE_CEAFSR_PDWR) ?
299 "DMA Write" : "???")));
300
301 /* XXX Use syndrome and afar to print out module string just like
302 * XXX UDB CE trap handler does... -DaveM
303 */
David S. Miller6c108f12007-05-07 23:49:01 -0700304 printk("%s: syndrome[%02lx] bytemask[%04lx] dword_offset[%lx] "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 "was_block(%d)\n",
David S. Miller6c108f12007-05-07 23:49:01 -0700306 pbm->name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 (afsr & SABRE_CEAFSR_ESYND) >> 48UL,
308 (afsr & SABRE_CEAFSR_BMSK) >> 32UL,
309 (afsr & SABRE_CEAFSR_OFF) >> 29UL,
310 ((afsr & SABRE_CEAFSR_BLK) ? 1 : 0));
David S. Miller6c108f12007-05-07 23:49:01 -0700311 printk("%s: CE AFAR [%016lx]\n", pbm->name, afar);
312 printk("%s: CE Secondary errors [", pbm->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 reported = 0;
314 if (afsr & SABRE_CEAFSR_SDRD) {
315 reported++;
316 printk("(DMA Read)");
317 }
318 if (afsr & SABRE_CEAFSR_SDWR) {
319 reported++;
320 printk("(DMA Write)");
321 }
322 if (!reported)
323 printk("(none)");
324 printk("]\n");
325
326 return IRQ_HANDLED;
327}
328
David S. Miller34768bc2007-05-07 23:06:27 -0700329static void sabre_register_error_handlers(struct pci_pbm_info *pbm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330{
David S. Miller22fecba2008-09-10 00:19:28 -0700331 struct device_node *dp = pbm->op->node;
David S. Miller2b1e5972006-06-29 15:07:37 -0700332 struct of_device *op;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 unsigned long base = pbm->controller_regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 u64 tmp;
David S. Milleraf803182007-05-08 17:23:31 -0700335 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336
David S. Miller2b1e5972006-06-29 15:07:37 -0700337 if (pbm->chip_type == PBM_CHIP_TYPE_SABRE)
338 dp = dp->parent;
339
340 op = of_find_device_by_node(dp);
341 if (!op)
342 return;
343
344 /* Sabre/Hummingbird IRQ property layout is:
345 * 0: PCI ERR
346 * 1: UE ERR
347 * 2: CE ERR
348 * 3: POWER FAIL
349 */
350 if (op->num_irqs < 4)
351 return;
352
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 /* We clear the error bits in the appropriate AFSR before
354 * registering the handler so that we don't get spurious
355 * interrupts.
356 */
357 sabre_write(base + SABRE_UE_AFSR,
358 (SABRE_UEAFSR_PDRD | SABRE_UEAFSR_PDWR |
359 SABRE_UEAFSR_SDRD | SABRE_UEAFSR_SDWR |
360 SABRE_UEAFSR_SDTE | SABRE_UEAFSR_PDTE));
David S. Miller2b1e5972006-06-29 15:07:37 -0700361
David S. Milleraf803182007-05-08 17:23:31 -0700362 err = request_irq(op->irqs[1], sabre_ue_intr, 0, "SABRE_UE", pbm);
363 if (err)
364 printk(KERN_WARNING "%s: Couldn't register UE, err=%d.\n",
365 pbm->name, err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
367 sabre_write(base + SABRE_CE_AFSR,
368 (SABRE_CEAFSR_PDRD | SABRE_CEAFSR_PDWR |
369 SABRE_CEAFSR_SDRD | SABRE_CEAFSR_SDWR));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
David S. Milleraf803182007-05-08 17:23:31 -0700371 err = request_irq(op->irqs[2], sabre_ce_intr, 0, "SABRE_CE", pbm);
372 if (err)
373 printk(KERN_WARNING "%s: Couldn't register CE, err=%d.\n",
374 pbm->name, err);
David S. Millere6e00372008-09-10 03:52:51 -0700375 err = request_irq(op->irqs[0], psycho_pcierr_intr, 0,
David S. Milleraf803182007-05-08 17:23:31 -0700376 "SABRE_PCIERR", pbm);
377 if (err)
378 printk(KERN_WARNING "%s: Couldn't register PCIERR, err=%d.\n",
379 pbm->name, err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380
381 tmp = sabre_read(base + SABRE_PCICTRL);
382 tmp |= SABRE_PCICTRL_ERREN;
383 sabre_write(base + SABRE_PCICTRL, tmp);
384}
385
David S. Miller34768bc2007-05-07 23:06:27 -0700386static void apb_init(struct pci_bus *sabre_bus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387{
388 struct pci_dev *pdev;
389
390 list_for_each_entry(pdev, &sabre_bus->devices, bus_list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 if (pdev->vendor == PCI_VENDOR_ID_SUN &&
392 pdev->device == PCI_DEVICE_ID_SUN_SIMBA) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 u16 word16;
394
David S. Miller01f94c42007-03-04 12:53:19 -0800395 pci_read_config_word(pdev, PCI_COMMAND, &word16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 word16 |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY |
397 PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY |
398 PCI_COMMAND_IO;
David S. Miller01f94c42007-03-04 12:53:19 -0800399 pci_write_config_word(pdev, PCI_COMMAND, word16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400
401 /* Status register bits are "write 1 to clear". */
David S. Miller01f94c42007-03-04 12:53:19 -0800402 pci_write_config_word(pdev, PCI_STATUS, 0xffff);
403 pci_write_config_word(pdev, PCI_SEC_STATUS, 0xffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
405 /* Use a primary/seconday latency timer value
406 * of 64.
407 */
David S. Miller01f94c42007-03-04 12:53:19 -0800408 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 64);
409 pci_write_config_byte(pdev, PCI_SEC_LATENCY_TIMER, 64);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
411 /* Enable reporting/forwarding of master aborts,
412 * parity, and SERR.
413 */
David S. Miller01f94c42007-03-04 12:53:19 -0800414 pci_write_config_byte(pdev, PCI_BRIDGE_CONTROL,
415 (PCI_BRIDGE_CTL_PARITY |
416 PCI_BRIDGE_CTL_SERR |
417 PCI_BRIDGE_CTL_MASTER_ABORT));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 }
419 }
420}
421
David S. Millere822358a2008-09-01 18:32:22 -0700422static void __init sabre_scan_bus(struct pci_pbm_info *pbm,
423 struct device *parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424{
425 static int once;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
427 /* The APB bridge speaks to the Sabre host PCI bridge
428 * at 66Mhz, but the front side of APB runs at 33Mhz
429 * for both segments.
David S. Miller321566c2007-06-06 14:03:08 -0700430 *
431 * Hummingbird systems do not use APB, so they run
432 * at 66MHZ.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 */
David S. Miller321566c2007-06-06 14:03:08 -0700434 if (hummingbird_p)
435 pbm->is_66mhz_capable = 1;
436 else
437 pbm->is_66mhz_capable = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438
439 /* This driver has not been verified to handle
440 * multiple SABREs yet, so trap this.
441 *
442 * Also note that the SABRE host bridge is hardwired
443 * to live at bus 0.
444 */
445 if (once != 0) {
David S. Milleredbe8052008-08-30 03:14:01 -0700446 printk(KERN_ERR PFX "Multiple controllers unsupported.\n");
447 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 }
449 once++;
450
David S. Millere822358a2008-09-01 18:32:22 -0700451 pbm->pci_bus = pci_scan_one_pbm(pbm, parent);
David S. Miller321566c2007-06-06 14:03:08 -0700452 if (!pbm->pci_bus)
David S. Millera2fb23a2007-02-28 23:35:04 -0800453 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454
David S. Miller321566c2007-06-06 14:03:08 -0700455 sabre_root_bus = pbm->pci_bus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456
David S. Miller321566c2007-06-06 14:03:08 -0700457 apb_init(pbm->pci_bus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458
David S. Miller34768bc2007-05-07 23:06:27 -0700459 sabre_register_error_handlers(pbm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460}
461
David S. Millerd3ae4b52008-09-09 23:54:02 -0700462static void __init sabre_pbm_init(struct pci_pbm_info *pbm,
463 struct of_device *op)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464{
David S. Miller1c03a552008-09-10 03:15:56 -0700465 psycho_pbm_init_common(pbm, op, "SABRE", PBM_CHIP_TYPE_SABRE);
David S. Millere6e00372008-09-10 03:52:51 -0700466 pbm->pci_afsr = pbm->controller_regs + SABRE_PIOAFSR;
467 pbm->pci_afar = pbm->controller_regs + SABRE_PIOAFAR;
468 pbm->pci_csr = pbm->controller_regs + SABRE_PCICTRL;
David S. Millere822358a2008-09-01 18:32:22 -0700469 sabre_scan_bus(pbm, &op->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470}
471
David S. Milleredbe8052008-08-30 03:14:01 -0700472static int __devinit sabre_probe(struct of_device *op,
473 const struct of_device_id *match)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474{
David S. Millera165b422007-03-29 01:50:16 -0700475 const struct linux_prom64_registers *pr_regs;
David S. Milleredbe8052008-08-30 03:14:01 -0700476 struct device_node *dp = op->node;
David S. Miller28113a92007-05-08 00:19:02 -0700477 struct pci_pbm_info *pbm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 u32 upa_portid, dma_mask;
David S. Milleredbe8052008-08-30 03:14:01 -0700479 struct iommu *iommu;
480 int tsbsize, err;
481 const u32 *vdma;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 u64 clear_irq;
483
David S. Milleredbe8052008-08-30 03:14:01 -0700484 hummingbird_p = (match->data != NULL);
485 if (!hummingbird_p) {
486 struct device_node *cpu_dp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
David S. Milleredbe8052008-08-30 03:14:01 -0700488 /* Of course, Sun has to encode things a thousand
489 * different ways, inconsistently.
490 */
491 for_each_node_by_type(cpu_dp, "cpu") {
492 if (!strcmp(cpu_dp->name, "SUNW,UltraSPARC-IIe"))
493 hummingbird_p = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 }
495 }
496
David S. Milleredbe8052008-08-30 03:14:01 -0700497 err = -ENOMEM;
David S. Millerd3ae4b52008-09-09 23:54:02 -0700498 pbm = kzalloc(sizeof(*pbm), GFP_KERNEL);
499 if (!pbm) {
500 printk(KERN_ERR PFX "Cannot allocate pci_pbm_info.\n");
David S. Millerd7472c32008-08-31 01:33:52 -0700501 goto out_err;
David S. Milleredbe8052008-08-30 03:14:01 -0700502 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503
David S. Millerd3ae4b52008-09-09 23:54:02 -0700504 iommu = kzalloc(sizeof(*iommu), GFP_KERNEL);
David S. Milleredbe8052008-08-30 03:14:01 -0700505 if (!iommu) {
506 printk(KERN_ERR PFX "Cannot allocate PBM iommu.\n");
David S. Millerd7472c32008-08-31 01:33:52 -0700507 goto out_free_controller;
David S. Milleredbe8052008-08-30 03:14:01 -0700508 }
509
David S. Miller28113a92007-05-08 00:19:02 -0700510 pbm->iommu = iommu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511
David S. Miller01f94c42007-03-04 12:53:19 -0800512 upa_portid = of_getintprop_default(dp, "upa-portid", 0xff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513
David S. Miller28113a92007-05-08 00:19:02 -0700514 pbm->portid = upa_portid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515
516 /*
517 * Map in SABRE register set and report the presence of this SABRE.
518 */
David S. Millere87dc352006-06-21 18:18:47 -0700519
David S. Miller01f94c42007-03-04 12:53:19 -0800520 pr_regs = of_get_property(dp, "reg", NULL);
David S. Milleredbe8052008-08-30 03:14:01 -0700521 err = -ENODEV;
522 if (!pr_regs) {
523 printk(KERN_ERR PFX "No reg property\n");
David S. Millerd7472c32008-08-31 01:33:52 -0700524 goto out_free_iommu;
David S. Milleredbe8052008-08-30 03:14:01 -0700525 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526
527 /*
528 * First REG in property is base of entire SABRE register space.
529 */
David S. Miller28113a92007-05-08 00:19:02 -0700530 pbm->controller_regs = pr_regs[0].phys_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 /* Clear interrupts */
533
534 /* PCI first */
535 for (clear_irq = SABRE_ICLR_A_SLOT0; clear_irq < SABRE_ICLR_B_SLOT0 + 0x80; clear_irq += 8)
David S. Miller28113a92007-05-08 00:19:02 -0700536 sabre_write(pbm->controller_regs + clear_irq, 0x0UL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537
538 /* Then OBIO */
539 for (clear_irq = SABRE_ICLR_SCSI; clear_irq < SABRE_ICLR_SCSI + 0x80; clear_irq += 8)
David S. Miller28113a92007-05-08 00:19:02 -0700540 sabre_write(pbm->controller_regs + clear_irq, 0x0UL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541
542 /* Error interrupts are enabled later after the bus scan. */
David S. Miller28113a92007-05-08 00:19:02 -0700543 sabre_write(pbm->controller_regs + SABRE_PCICTRL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 (SABRE_PCICTRL_MRLEN | SABRE_PCICTRL_SERR |
545 SABRE_PCICTRL_ARBPARK | SABRE_PCICTRL_AEN));
546
547 /* Now map in PCI config space for entire SABRE. */
David S. Millerd3ae4b52008-09-09 23:54:02 -0700548 pbm->config_space = pbm->controller_regs + SABRE_CONFIGSPACE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
David S. Miller01f94c42007-03-04 12:53:19 -0800550 vdma = of_get_property(dp, "virtual-dma", NULL);
David S. Milleredbe8052008-08-30 03:14:01 -0700551 if (!vdma) {
552 printk(KERN_ERR PFX "No virtual-dma property\n");
David S. Millerd7472c32008-08-31 01:33:52 -0700553 goto out_free_iommu;
David S. Milleredbe8052008-08-30 03:14:01 -0700554 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
556 dma_mask = vdma[0];
557 switch(vdma[1]) {
558 case 0x20000000:
559 dma_mask |= 0x1fffffff;
560 tsbsize = 64;
561 break;
562 case 0x40000000:
563 dma_mask |= 0x3fffffff;
564 tsbsize = 128;
565 break;
566
567 case 0x80000000:
568 dma_mask |= 0x7fffffff;
569 tsbsize = 128;
570 break;
571 default:
David S. Milleredbe8052008-08-30 03:14:01 -0700572 printk(KERN_ERR PFX "Strange virtual-dma size.\n");
David S. Millerd7472c32008-08-31 01:33:52 -0700573 goto out_free_iommu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 }
575
David S. Millera21cff32008-09-10 03:07:03 -0700576 err = psycho_iommu_init(pbm, tsbsize, vdma[0], dma_mask, SABRE_WRSYNC);
David S. Milleredbe8052008-08-30 03:14:01 -0700577 if (err)
David S. Millerd7472c32008-08-31 01:33:52 -0700578 goto out_free_iommu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 /*
581 * Look for APB underneath.
582 */
David S. Millerd3ae4b52008-09-09 23:54:02 -0700583 sabre_pbm_init(pbm, op);
584
585 pbm->next = pci_pbm_root;
586 pci_pbm_root = pbm;
587
588 dev_set_drvdata(&op->dev, pbm);
589
David S. Milleredbe8052008-08-30 03:14:01 -0700590 return 0;
David S. Millerad7ad572007-07-27 22:39:14 -0700591
David S. Millerd7472c32008-08-31 01:33:52 -0700592out_free_iommu:
David S. Millerd3ae4b52008-09-09 23:54:02 -0700593 kfree(pbm->iommu);
David S. Millerd7472c32008-08-31 01:33:52 -0700594
595out_free_controller:
David S. Millerd3ae4b52008-09-09 23:54:02 -0700596 kfree(pbm);
David S. Millerd7472c32008-08-31 01:33:52 -0700597
598out_err:
David S. Milleredbe8052008-08-30 03:14:01 -0700599 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600}
David S. Milleredbe8052008-08-30 03:14:01 -0700601
David S. Millerfd098312008-08-31 01:23:17 -0700602static struct of_device_id __initdata sabre_match[] = {
David S. Milleredbe8052008-08-30 03:14:01 -0700603 {
604 .name = "pci",
605 .compatible = "pci108e,a001",
606 .data = (void *) 1,
607 },
608 {
609 .name = "pci",
610 .compatible = "pci108e,a000",
611 },
612 {},
613};
614
615static struct of_platform_driver sabre_driver = {
616 .name = DRIVER_NAME,
617 .match_table = sabre_match,
618 .probe = sabre_probe,
619};
620
621static int __init sabre_init(void)
622{
623 return of_register_driver(&sabre_driver, &of_bus_type);
624}
625
626subsys_initcall(sabre_init);