pci_psycho.c 22 KB

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