pci_psycho.c 23 KB

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