pci_psycho.c 22 KB

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