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