pci_psycho.c 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078
  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/oplib.h>
  19. #include "pci_impl.h"
  20. #include "iommu_common.h"
  21. /* All PSYCHO registers are 64-bits. The following accessor
  22. * routines are how they are accessed. The REG parameter
  23. * is a physical address.
  24. */
  25. #define psycho_read(__reg) \
  26. ({ u64 __ret; \
  27. __asm__ __volatile__("ldxa [%1] %2, %0" \
  28. : "=r" (__ret) \
  29. : "r" (__reg), "i" (ASI_PHYS_BYPASS_EC_E) \
  30. : "memory"); \
  31. __ret; \
  32. })
  33. #define psycho_write(__reg, __val) \
  34. __asm__ __volatile__("stxa %0, [%1] %2" \
  35. : /* no outputs */ \
  36. : "r" (__val), "r" (__reg), \
  37. "i" (ASI_PHYS_BYPASS_EC_E) \
  38. : "memory")
  39. /* Misc. PSYCHO PCI controller register offsets and definitions. */
  40. #define PSYCHO_CONTROL 0x0010UL
  41. #define PSYCHO_CONTROL_IMPL 0xf000000000000000UL /* Implementation of this PSYCHO*/
  42. #define PSYCHO_CONTROL_VER 0x0f00000000000000UL /* Version of this PSYCHO */
  43. #define PSYCHO_CONTROL_MID 0x00f8000000000000UL /* UPA Module ID of PSYCHO */
  44. #define PSYCHO_CONTROL_IGN 0x0007c00000000000UL /* Interrupt Group Number */
  45. #define PSYCHO_CONTROL_RESV 0x00003ffffffffff0UL /* Reserved */
  46. #define PSYCHO_CONTROL_APCKEN 0x0000000000000008UL /* Address Parity Check Enable */
  47. #define PSYCHO_CONTROL_APERR 0x0000000000000004UL /* Incoming System Addr Parerr */
  48. #define PSYCHO_CONTROL_IAP 0x0000000000000002UL /* Invert UPA Parity */
  49. #define PSYCHO_CONTROL_MODE 0x0000000000000001UL /* PSYCHO clock mode */
  50. #define PSYCHO_PCIA_CTRL 0x2000UL
  51. #define PSYCHO_PCIB_CTRL 0x4000UL
  52. #define PSYCHO_PCICTRL_RESV1 0xfffffff000000000UL /* Reserved */
  53. #define PSYCHO_PCICTRL_SBH_ERR 0x0000000800000000UL /* Streaming byte hole error */
  54. #define PSYCHO_PCICTRL_SERR 0x0000000400000000UL /* SERR signal asserted */
  55. #define PSYCHO_PCICTRL_SPEED 0x0000000200000000UL /* PCI speed (1 is U2P clock) */
  56. #define PSYCHO_PCICTRL_RESV2 0x00000001ffc00000UL /* Reserved */
  57. #define PSYCHO_PCICTRL_ARB_PARK 0x0000000000200000UL /* PCI arbitration parking */
  58. #define PSYCHO_PCICTRL_RESV3 0x00000000001ff800UL /* Reserved */
  59. #define PSYCHO_PCICTRL_SBH_INT 0x0000000000000400UL /* Streaming byte hole int enab */
  60. #define PSYCHO_PCICTRL_WEN 0x0000000000000200UL /* Power Mgmt Wake Enable */
  61. #define PSYCHO_PCICTRL_EEN 0x0000000000000100UL /* PCI Error Interrupt Enable */
  62. #define PSYCHO_PCICTRL_RESV4 0x00000000000000c0UL /* Reserved */
  63. #define PSYCHO_PCICTRL_AEN 0x000000000000003fUL /* PCI DVMA Arbitration Enable */
  64. /* U2P Programmer's Manual, page 13-55, configuration space
  65. * address format:
  66. *
  67. * 32 24 23 16 15 11 10 8 7 2 1 0
  68. * ---------------------------------------------------------
  69. * |0 0 0 0 0 0 0 0 1| bus | device | function | reg | 0 0 |
  70. * ---------------------------------------------------------
  71. */
  72. #define PSYCHO_CONFIG_BASE(PBM) \
  73. ((PBM)->config_space | (1UL << 24))
  74. #define PSYCHO_CONFIG_ENCODE(BUS, DEVFN, REG) \
  75. (((unsigned long)(BUS) << 16) | \
  76. ((unsigned long)(DEVFN) << 8) | \
  77. ((unsigned long)(REG)))
  78. static void *psycho_pci_config_mkaddr(struct pci_pbm_info *pbm,
  79. unsigned char bus,
  80. unsigned int devfn,
  81. int where)
  82. {
  83. if (!pbm)
  84. return NULL;
  85. return (void *)
  86. (PSYCHO_CONFIG_BASE(pbm) |
  87. PSYCHO_CONFIG_ENCODE(bus, devfn, where));
  88. }
  89. /* PSYCHO error handling support. */
  90. enum psycho_error_type {
  91. UE_ERR, CE_ERR, PCI_ERR
  92. };
  93. /* Helper function of IOMMU error checking, which checks out
  94. * the state of the streaming buffers. The IOMMU lock is
  95. * held when this is called.
  96. *
  97. * For the PCI error case we know which PBM (and thus which
  98. * streaming buffer) caused the error, but for the uncorrectable
  99. * error case we do not. So we always check both streaming caches.
  100. */
  101. #define PSYCHO_STRBUF_CONTROL_A 0x2800UL
  102. #define PSYCHO_STRBUF_CONTROL_B 0x4800UL
  103. #define PSYCHO_STRBUF_CTRL_LPTR 0x00000000000000f0UL /* LRU Lock Pointer */
  104. #define PSYCHO_STRBUF_CTRL_LENAB 0x0000000000000008UL /* LRU Lock Enable */
  105. #define PSYCHO_STRBUF_CTRL_RRDIS 0x0000000000000004UL /* Rerun Disable */
  106. #define PSYCHO_STRBUF_CTRL_DENAB 0x0000000000000002UL /* Diagnostic Mode Enable */
  107. #define PSYCHO_STRBUF_CTRL_ENAB 0x0000000000000001UL /* Streaming Buffer Enable */
  108. #define PSYCHO_STRBUF_FLUSH_A 0x2808UL
  109. #define PSYCHO_STRBUF_FLUSH_B 0x4808UL
  110. #define PSYCHO_STRBUF_FSYNC_A 0x2810UL
  111. #define PSYCHO_STRBUF_FSYNC_B 0x4810UL
  112. #define PSYCHO_STC_DATA_A 0xb000UL
  113. #define PSYCHO_STC_DATA_B 0xc000UL
  114. #define PSYCHO_STC_ERR_A 0xb400UL
  115. #define PSYCHO_STC_ERR_B 0xc400UL
  116. #define PSYCHO_STCERR_WRITE 0x0000000000000002UL /* Write Error */
  117. #define PSYCHO_STCERR_READ 0x0000000000000001UL /* Read Error */
  118. #define PSYCHO_STC_TAG_A 0xb800UL
  119. #define PSYCHO_STC_TAG_B 0xc800UL
  120. #define PSYCHO_STCTAG_PPN 0x0fffffff00000000UL /* Physical Page Number */
  121. #define PSYCHO_STCTAG_VPN 0x00000000ffffe000UL /* Virtual Page Number */
  122. #define PSYCHO_STCTAG_VALID 0x0000000000000002UL /* Valid */
  123. #define PSYCHO_STCTAG_WRITE 0x0000000000000001UL /* Writable */
  124. #define PSYCHO_STC_LINE_A 0xb900UL
  125. #define PSYCHO_STC_LINE_B 0xc900UL
  126. #define PSYCHO_STCLINE_LINDX 0x0000000001e00000UL /* LRU Index */
  127. #define PSYCHO_STCLINE_SPTR 0x00000000001f8000UL /* Dirty Data Start Pointer */
  128. #define PSYCHO_STCLINE_LADDR 0x0000000000007f00UL /* Line Address */
  129. #define PSYCHO_STCLINE_EPTR 0x00000000000000fcUL /* Dirty Data End Pointer */
  130. #define PSYCHO_STCLINE_VALID 0x0000000000000002UL /* Valid */
  131. #define PSYCHO_STCLINE_FOFN 0x0000000000000001UL /* Fetch Outstanding / Flush Necessary */
  132. static DEFINE_SPINLOCK(stc_buf_lock);
  133. static unsigned long stc_error_buf[128];
  134. static unsigned long stc_tag_buf[16];
  135. static unsigned long stc_line_buf[16];
  136. static void __psycho_check_one_stc(struct pci_pbm_info *pbm,
  137. int is_pbm_a)
  138. {
  139. struct strbuf *strbuf = &pbm->stc;
  140. unsigned long regbase = pbm->controller_regs;
  141. unsigned long err_base, tag_base, line_base;
  142. u64 control;
  143. int i;
  144. if (is_pbm_a) {
  145. err_base = regbase + PSYCHO_STC_ERR_A;
  146. tag_base = regbase + PSYCHO_STC_TAG_A;
  147. line_base = regbase + PSYCHO_STC_LINE_A;
  148. } else {
  149. err_base = regbase + PSYCHO_STC_ERR_B;
  150. tag_base = regbase + PSYCHO_STC_TAG_B;
  151. line_base = regbase + PSYCHO_STC_LINE_B;
  152. }
  153. spin_lock(&stc_buf_lock);
  154. /* This is __REALLY__ dangerous. When we put the
  155. * streaming buffer into diagnostic mode to probe
  156. * it's tags and error status, we _must_ clear all
  157. * of the line tag valid bits before re-enabling
  158. * the streaming buffer. If any dirty data lives
  159. * in the STC when we do this, we will end up
  160. * invalidating it before it has a chance to reach
  161. * main memory.
  162. */
  163. control = psycho_read(strbuf->strbuf_control);
  164. psycho_write(strbuf->strbuf_control,
  165. (control | PSYCHO_STRBUF_CTRL_DENAB));
  166. for (i = 0; i < 128; i++) {
  167. unsigned long val;
  168. val = psycho_read(err_base + (i * 8UL));
  169. psycho_write(err_base + (i * 8UL), 0UL);
  170. stc_error_buf[i] = val;
  171. }
  172. for (i = 0; i < 16; i++) {
  173. stc_tag_buf[i] = psycho_read(tag_base + (i * 8UL));
  174. stc_line_buf[i] = psycho_read(line_base + (i * 8UL));
  175. psycho_write(tag_base + (i * 8UL), 0UL);
  176. psycho_write(line_base + (i * 8UL), 0UL);
  177. }
  178. /* OK, state is logged, exit diagnostic mode. */
  179. psycho_write(strbuf->strbuf_control, control);
  180. for (i = 0; i < 16; i++) {
  181. int j, saw_error, first, last;
  182. saw_error = 0;
  183. first = i * 8;
  184. last = first + 8;
  185. for (j = first; j < last; j++) {
  186. unsigned long errval = stc_error_buf[j];
  187. if (errval != 0) {
  188. saw_error++;
  189. printk("%s: STC_ERR(%d)[wr(%d)rd(%d)]\n",
  190. pbm->name,
  191. j,
  192. (errval & PSYCHO_STCERR_WRITE) ? 1 : 0,
  193. (errval & PSYCHO_STCERR_READ) ? 1 : 0);
  194. }
  195. }
  196. if (saw_error != 0) {
  197. unsigned long tagval = stc_tag_buf[i];
  198. unsigned long lineval = stc_line_buf[i];
  199. printk("%s: STC_TAG(%d)[PA(%016lx)VA(%08lx)V(%d)W(%d)]\n",
  200. pbm->name,
  201. i,
  202. ((tagval & PSYCHO_STCTAG_PPN) >> 19UL),
  203. (tagval & PSYCHO_STCTAG_VPN),
  204. ((tagval & PSYCHO_STCTAG_VALID) ? 1 : 0),
  205. ((tagval & PSYCHO_STCTAG_WRITE) ? 1 : 0));
  206. printk("%s: STC_LINE(%d)[LIDX(%lx)SP(%lx)LADDR(%lx)EP(%lx)"
  207. "V(%d)FOFN(%d)]\n",
  208. pbm->name,
  209. i,
  210. ((lineval & PSYCHO_STCLINE_LINDX) >> 21UL),
  211. ((lineval & PSYCHO_STCLINE_SPTR) >> 15UL),
  212. ((lineval & PSYCHO_STCLINE_LADDR) >> 8UL),
  213. ((lineval & PSYCHO_STCLINE_EPTR) >> 2UL),
  214. ((lineval & PSYCHO_STCLINE_VALID) ? 1 : 0),
  215. ((lineval & PSYCHO_STCLINE_FOFN) ? 1 : 0));
  216. }
  217. }
  218. spin_unlock(&stc_buf_lock);
  219. }
  220. static void __psycho_check_stc_error(struct pci_pbm_info *pbm,
  221. unsigned long afsr,
  222. unsigned long afar,
  223. enum psycho_error_type type)
  224. {
  225. __psycho_check_one_stc(pbm,
  226. (pbm == &pbm->parent->pbm_A));
  227. }
  228. /* When an Uncorrectable Error or a PCI Error happens, we
  229. * interrogate the IOMMU state to see if it is the cause.
  230. */
  231. #define PSYCHO_IOMMU_CONTROL 0x0200UL
  232. #define PSYCHO_IOMMU_CTRL_RESV 0xfffffffff9000000UL /* Reserved */
  233. #define PSYCHO_IOMMU_CTRL_XLTESTAT 0x0000000006000000UL /* Translation Error Status */
  234. #define PSYCHO_IOMMU_CTRL_XLTEERR 0x0000000001000000UL /* Translation Error encountered */
  235. #define PSYCHO_IOMMU_CTRL_LCKEN 0x0000000000800000UL /* Enable translation locking */
  236. #define PSYCHO_IOMMU_CTRL_LCKPTR 0x0000000000780000UL /* Translation lock pointer */
  237. #define PSYCHO_IOMMU_CTRL_TSBSZ 0x0000000000070000UL /* TSB Size */
  238. #define PSYCHO_IOMMU_TSBSZ_1K 0x0000000000000000UL /* TSB Table 1024 8-byte entries */
  239. #define PSYCHO_IOMMU_TSBSZ_2K 0x0000000000010000UL /* TSB Table 2048 8-byte entries */
  240. #define PSYCHO_IOMMU_TSBSZ_4K 0x0000000000020000UL /* TSB Table 4096 8-byte entries */
  241. #define PSYCHO_IOMMU_TSBSZ_8K 0x0000000000030000UL /* TSB Table 8192 8-byte entries */
  242. #define PSYCHO_IOMMU_TSBSZ_16K 0x0000000000040000UL /* TSB Table 16k 8-byte entries */
  243. #define PSYCHO_IOMMU_TSBSZ_32K 0x0000000000050000UL /* TSB Table 32k 8-byte entries */
  244. #define PSYCHO_IOMMU_TSBSZ_64K 0x0000000000060000UL /* TSB Table 64k 8-byte entries */
  245. #define PSYCHO_IOMMU_TSBSZ_128K 0x0000000000070000UL /* TSB Table 128k 8-byte entries */
  246. #define PSYCHO_IOMMU_CTRL_RESV2 0x000000000000fff8UL /* Reserved */
  247. #define PSYCHO_IOMMU_CTRL_TBWSZ 0x0000000000000004UL /* Assumed page size, 0=8k 1=64k */
  248. #define PSYCHO_IOMMU_CTRL_DENAB 0x0000000000000002UL /* Diagnostic mode enable */
  249. #define PSYCHO_IOMMU_CTRL_ENAB 0x0000000000000001UL /* IOMMU Enable */
  250. #define PSYCHO_IOMMU_TSBBASE 0x0208UL
  251. #define PSYCHO_IOMMU_FLUSH 0x0210UL
  252. #define PSYCHO_IOMMU_TAG 0xa580UL
  253. #define PSYCHO_IOMMU_TAG_ERRSTS (0x3UL << 23UL)
  254. #define PSYCHO_IOMMU_TAG_ERR (0x1UL << 22UL)
  255. #define PSYCHO_IOMMU_TAG_WRITE (0x1UL << 21UL)
  256. #define PSYCHO_IOMMU_TAG_STREAM (0x1UL << 20UL)
  257. #define PSYCHO_IOMMU_TAG_SIZE (0x1UL << 19UL)
  258. #define PSYCHO_IOMMU_TAG_VPAGE 0x7ffffUL
  259. #define PSYCHO_IOMMU_DATA 0xa600UL
  260. #define PSYCHO_IOMMU_DATA_VALID (1UL << 30UL)
  261. #define PSYCHO_IOMMU_DATA_CACHE (1UL << 28UL)
  262. #define PSYCHO_IOMMU_DATA_PPAGE 0xfffffffUL
  263. static void psycho_check_iommu_error(struct pci_pbm_info *pbm,
  264. unsigned long afsr,
  265. unsigned long afar,
  266. enum psycho_error_type type)
  267. {
  268. struct iommu *iommu = pbm->iommu;
  269. unsigned long iommu_tag[16];
  270. unsigned long iommu_data[16];
  271. unsigned long flags;
  272. u64 control;
  273. int i;
  274. spin_lock_irqsave(&iommu->lock, flags);
  275. control = psycho_read(iommu->iommu_control);
  276. if (control & PSYCHO_IOMMU_CTRL_XLTEERR) {
  277. char *type_string;
  278. /* Clear the error encountered bit. */
  279. control &= ~PSYCHO_IOMMU_CTRL_XLTEERR;
  280. psycho_write(iommu->iommu_control, control);
  281. switch((control & PSYCHO_IOMMU_CTRL_XLTESTAT) >> 25UL) {
  282. case 0:
  283. type_string = "Protection Error";
  284. break;
  285. case 1:
  286. type_string = "Invalid Error";
  287. break;
  288. case 2:
  289. type_string = "TimeOut Error";
  290. break;
  291. case 3:
  292. default:
  293. type_string = "ECC Error";
  294. break;
  295. };
  296. printk("%s: IOMMU Error, type[%s]\n",
  297. pbm->name, type_string);
  298. /* Put the IOMMU into diagnostic mode and probe
  299. * it's TLB for entries with error status.
  300. *
  301. * It is very possible for another DVMA to occur
  302. * while we do this probe, and corrupt the system
  303. * further. But we are so screwed at this point
  304. * that we are likely to crash hard anyways, so
  305. * get as much diagnostic information to the
  306. * console as we can.
  307. */
  308. psycho_write(iommu->iommu_control,
  309. control | PSYCHO_IOMMU_CTRL_DENAB);
  310. for (i = 0; i < 16; i++) {
  311. unsigned long base = pbm->controller_regs;
  312. iommu_tag[i] =
  313. psycho_read(base + PSYCHO_IOMMU_TAG + (i * 8UL));
  314. iommu_data[i] =
  315. psycho_read(base + PSYCHO_IOMMU_DATA + (i * 8UL));
  316. /* Now clear out the entry. */
  317. psycho_write(base + PSYCHO_IOMMU_TAG + (i * 8UL), 0);
  318. psycho_write(base + PSYCHO_IOMMU_DATA + (i * 8UL), 0);
  319. }
  320. /* Leave diagnostic mode. */
  321. psycho_write(iommu->iommu_control, control);
  322. for (i = 0; i < 16; i++) {
  323. unsigned long tag, data;
  324. tag = iommu_tag[i];
  325. if (!(tag & PSYCHO_IOMMU_TAG_ERR))
  326. continue;
  327. data = iommu_data[i];
  328. switch((tag & PSYCHO_IOMMU_TAG_ERRSTS) >> 23UL) {
  329. case 0:
  330. type_string = "Protection Error";
  331. break;
  332. case 1:
  333. type_string = "Invalid Error";
  334. break;
  335. case 2:
  336. type_string = "TimeOut Error";
  337. break;
  338. case 3:
  339. default:
  340. type_string = "ECC Error";
  341. break;
  342. };
  343. printk("%s: IOMMU TAG(%d)[error(%s) wr(%d) str(%d) sz(%dK) vpg(%08lx)]\n",
  344. pbm->name, i, type_string,
  345. ((tag & PSYCHO_IOMMU_TAG_WRITE) ? 1 : 0),
  346. ((tag & PSYCHO_IOMMU_TAG_STREAM) ? 1 : 0),
  347. ((tag & PSYCHO_IOMMU_TAG_SIZE) ? 64 : 8),
  348. (tag & PSYCHO_IOMMU_TAG_VPAGE) << IOMMU_PAGE_SHIFT);
  349. printk("%s: IOMMU DATA(%d)[valid(%d) cache(%d) ppg(%016lx)]\n",
  350. pbm->name, i,
  351. ((data & PSYCHO_IOMMU_DATA_VALID) ? 1 : 0),
  352. ((data & PSYCHO_IOMMU_DATA_CACHE) ? 1 : 0),
  353. (data & PSYCHO_IOMMU_DATA_PPAGE) << IOMMU_PAGE_SHIFT);
  354. }
  355. }
  356. __psycho_check_stc_error(pbm, afsr, afar, type);
  357. spin_unlock_irqrestore(&iommu->lock, flags);
  358. }
  359. /* Uncorrectable Errors. Cause of the error and the address are
  360. * recorded in the UE_AFSR and UE_AFAR of PSYCHO. They are errors
  361. * relating to UPA interface transactions.
  362. */
  363. #define PSYCHO_UE_AFSR 0x0030UL
  364. #define PSYCHO_UEAFSR_PPIO 0x8000000000000000UL /* Primary PIO is cause */
  365. #define PSYCHO_UEAFSR_PDRD 0x4000000000000000UL /* Primary DVMA read is cause */
  366. #define PSYCHO_UEAFSR_PDWR 0x2000000000000000UL /* Primary DVMA write is cause */
  367. #define PSYCHO_UEAFSR_SPIO 0x1000000000000000UL /* Secondary PIO is cause */
  368. #define PSYCHO_UEAFSR_SDRD 0x0800000000000000UL /* Secondary DVMA read is cause */
  369. #define PSYCHO_UEAFSR_SDWR 0x0400000000000000UL /* Secondary DVMA write is cause*/
  370. #define PSYCHO_UEAFSR_RESV1 0x03ff000000000000UL /* Reserved */
  371. #define PSYCHO_UEAFSR_BMSK 0x0000ffff00000000UL /* Bytemask of failed transfer */
  372. #define PSYCHO_UEAFSR_DOFF 0x00000000e0000000UL /* Doubleword Offset */
  373. #define PSYCHO_UEAFSR_MID 0x000000001f000000UL /* UPA MID causing the fault */
  374. #define PSYCHO_UEAFSR_BLK 0x0000000000800000UL /* Trans was block operation */
  375. #define PSYCHO_UEAFSR_RESV2 0x00000000007fffffUL /* Reserved */
  376. #define PSYCHO_UE_AFAR 0x0038UL
  377. static irqreturn_t psycho_ue_intr(int irq, void *dev_id)
  378. {
  379. struct pci_pbm_info *pbm = dev_id;
  380. struct pci_controller_info *p = pbm->parent;
  381. unsigned long afsr_reg = pbm->controller_regs + PSYCHO_UE_AFSR;
  382. unsigned long afar_reg = pbm->controller_regs + PSYCHO_UE_AFAR;
  383. unsigned long afsr, afar, error_bits;
  384. int reported;
  385. /* Latch uncorrectable error status. */
  386. afar = psycho_read(afar_reg);
  387. afsr = psycho_read(afsr_reg);
  388. /* Clear the primary/secondary error status bits. */
  389. error_bits = afsr &
  390. (PSYCHO_UEAFSR_PPIO | PSYCHO_UEAFSR_PDRD | PSYCHO_UEAFSR_PDWR |
  391. PSYCHO_UEAFSR_SPIO | PSYCHO_UEAFSR_SDRD | PSYCHO_UEAFSR_SDWR);
  392. if (!error_bits)
  393. return IRQ_NONE;
  394. psycho_write(afsr_reg, error_bits);
  395. /* Log the error. */
  396. printk("%s: Uncorrectable Error, primary error type[%s]\n",
  397. pbm->name,
  398. (((error_bits & PSYCHO_UEAFSR_PPIO) ?
  399. "PIO" :
  400. ((error_bits & PSYCHO_UEAFSR_PDRD) ?
  401. "DMA Read" :
  402. ((error_bits & PSYCHO_UEAFSR_PDWR) ?
  403. "DMA Write" : "???")))));
  404. printk("%s: bytemask[%04lx] dword_offset[%lx] UPA_MID[%02lx] was_block(%d)\n",
  405. pbm->name,
  406. (afsr & PSYCHO_UEAFSR_BMSK) >> 32UL,
  407. (afsr & PSYCHO_UEAFSR_DOFF) >> 29UL,
  408. (afsr & PSYCHO_UEAFSR_MID) >> 24UL,
  409. ((afsr & PSYCHO_UEAFSR_BLK) ? 1 : 0));
  410. printk("%s: UE AFAR [%016lx]\n", pbm->name, afar);
  411. printk("%s: UE Secondary errors [", pbm->name);
  412. reported = 0;
  413. if (afsr & PSYCHO_UEAFSR_SPIO) {
  414. reported++;
  415. printk("(PIO)");
  416. }
  417. if (afsr & PSYCHO_UEAFSR_SDRD) {
  418. reported++;
  419. printk("(DMA Read)");
  420. }
  421. if (afsr & PSYCHO_UEAFSR_SDWR) {
  422. reported++;
  423. printk("(DMA Write)");
  424. }
  425. if (!reported)
  426. printk("(none)");
  427. printk("]\n");
  428. /* Interrogate both IOMMUs for error status. */
  429. psycho_check_iommu_error(&p->pbm_A, afsr, afar, UE_ERR);
  430. psycho_check_iommu_error(&p->pbm_B, afsr, afar, UE_ERR);
  431. return IRQ_HANDLED;
  432. }
  433. /* Correctable Errors. */
  434. #define PSYCHO_CE_AFSR 0x0040UL
  435. #define PSYCHO_CEAFSR_PPIO 0x8000000000000000UL /* Primary PIO is cause */
  436. #define PSYCHO_CEAFSR_PDRD 0x4000000000000000UL /* Primary DVMA read is cause */
  437. #define PSYCHO_CEAFSR_PDWR 0x2000000000000000UL /* Primary DVMA write is cause */
  438. #define PSYCHO_CEAFSR_SPIO 0x1000000000000000UL /* Secondary PIO is cause */
  439. #define PSYCHO_CEAFSR_SDRD 0x0800000000000000UL /* Secondary DVMA read is cause */
  440. #define PSYCHO_CEAFSR_SDWR 0x0400000000000000UL /* Secondary DVMA write is cause*/
  441. #define PSYCHO_CEAFSR_RESV1 0x0300000000000000UL /* Reserved */
  442. #define PSYCHO_CEAFSR_ESYND 0x00ff000000000000UL /* Syndrome Bits */
  443. #define PSYCHO_CEAFSR_BMSK 0x0000ffff00000000UL /* Bytemask of failed transfer */
  444. #define PSYCHO_CEAFSR_DOFF 0x00000000e0000000UL /* Double Offset */
  445. #define PSYCHO_CEAFSR_MID 0x000000001f000000UL /* UPA MID causing the fault */
  446. #define PSYCHO_CEAFSR_BLK 0x0000000000800000UL /* Trans was block operation */
  447. #define PSYCHO_CEAFSR_RESV2 0x00000000007fffffUL /* Reserved */
  448. #define PSYCHO_CE_AFAR 0x0040UL
  449. static irqreturn_t psycho_ce_intr(int irq, void *dev_id)
  450. {
  451. struct pci_pbm_info *pbm = dev_id;
  452. unsigned long afsr_reg = pbm->controller_regs + PSYCHO_CE_AFSR;
  453. unsigned long afar_reg = pbm->controller_regs + PSYCHO_CE_AFAR;
  454. unsigned long afsr, afar, error_bits;
  455. int reported;
  456. /* Latch error status. */
  457. afar = psycho_read(afar_reg);
  458. afsr = psycho_read(afsr_reg);
  459. /* Clear primary/secondary error status bits. */
  460. error_bits = afsr &
  461. (PSYCHO_CEAFSR_PPIO | PSYCHO_CEAFSR_PDRD | PSYCHO_CEAFSR_PDWR |
  462. PSYCHO_CEAFSR_SPIO | PSYCHO_CEAFSR_SDRD | PSYCHO_CEAFSR_SDWR);
  463. if (!error_bits)
  464. return IRQ_NONE;
  465. psycho_write(afsr_reg, error_bits);
  466. /* Log the error. */
  467. printk("%s: Correctable Error, primary error type[%s]\n",
  468. pbm->name,
  469. (((error_bits & PSYCHO_CEAFSR_PPIO) ?
  470. "PIO" :
  471. ((error_bits & PSYCHO_CEAFSR_PDRD) ?
  472. "DMA Read" :
  473. ((error_bits & PSYCHO_CEAFSR_PDWR) ?
  474. "DMA Write" : "???")))));
  475. /* XXX Use syndrome and afar to print out module string just like
  476. * XXX UDB CE trap handler does... -DaveM
  477. */
  478. printk("%s: syndrome[%02lx] bytemask[%04lx] dword_offset[%lx] "
  479. "UPA_MID[%02lx] was_block(%d)\n",
  480. pbm->name,
  481. (afsr & PSYCHO_CEAFSR_ESYND) >> 48UL,
  482. (afsr & PSYCHO_CEAFSR_BMSK) >> 32UL,
  483. (afsr & PSYCHO_CEAFSR_DOFF) >> 29UL,
  484. (afsr & PSYCHO_CEAFSR_MID) >> 24UL,
  485. ((afsr & PSYCHO_CEAFSR_BLK) ? 1 : 0));
  486. printk("%s: CE AFAR [%016lx]\n", pbm->name, afar);
  487. printk("%s: CE Secondary errors [", pbm->name);
  488. reported = 0;
  489. if (afsr & PSYCHO_CEAFSR_SPIO) {
  490. reported++;
  491. printk("(PIO)");
  492. }
  493. if (afsr & PSYCHO_CEAFSR_SDRD) {
  494. reported++;
  495. printk("(DMA Read)");
  496. }
  497. if (afsr & PSYCHO_CEAFSR_SDWR) {
  498. reported++;
  499. printk("(DMA Write)");
  500. }
  501. if (!reported)
  502. printk("(none)");
  503. printk("]\n");
  504. return IRQ_HANDLED;
  505. }
  506. /* PCI Errors. They are signalled by the PCI bus module since they
  507. * are associated with a specific bus segment.
  508. */
  509. #define PSYCHO_PCI_AFSR_A 0x2010UL
  510. #define PSYCHO_PCI_AFSR_B 0x4010UL
  511. #define PSYCHO_PCIAFSR_PMA 0x8000000000000000UL /* Primary Master Abort Error */
  512. #define PSYCHO_PCIAFSR_PTA 0x4000000000000000UL /* Primary Target Abort Error */
  513. #define PSYCHO_PCIAFSR_PRTRY 0x2000000000000000UL /* Primary Excessive Retries */
  514. #define PSYCHO_PCIAFSR_PPERR 0x1000000000000000UL /* Primary Parity Error */
  515. #define PSYCHO_PCIAFSR_SMA 0x0800000000000000UL /* Secondary Master Abort Error */
  516. #define PSYCHO_PCIAFSR_STA 0x0400000000000000UL /* Secondary Target Abort Error */
  517. #define PSYCHO_PCIAFSR_SRTRY 0x0200000000000000UL /* Secondary Excessive Retries */
  518. #define PSYCHO_PCIAFSR_SPERR 0x0100000000000000UL /* Secondary Parity Error */
  519. #define PSYCHO_PCIAFSR_RESV1 0x00ff000000000000UL /* Reserved */
  520. #define PSYCHO_PCIAFSR_BMSK 0x0000ffff00000000UL /* Bytemask of failed transfer */
  521. #define PSYCHO_PCIAFSR_BLK 0x0000000080000000UL /* Trans was block operation */
  522. #define PSYCHO_PCIAFSR_RESV2 0x0000000040000000UL /* Reserved */
  523. #define PSYCHO_PCIAFSR_MID 0x000000003e000000UL /* MID causing the error */
  524. #define PSYCHO_PCIAFSR_RESV3 0x0000000001ffffffUL /* Reserved */
  525. #define PSYCHO_PCI_AFAR_A 0x2018UL
  526. #define PSYCHO_PCI_AFAR_B 0x4018UL
  527. static irqreturn_t psycho_pcierr_intr_other(struct pci_pbm_info *pbm, int is_pbm_a)
  528. {
  529. unsigned long csr_reg, csr, csr_error_bits;
  530. irqreturn_t ret = IRQ_NONE;
  531. u16 stat, *addr;
  532. if (is_pbm_a) {
  533. csr_reg = pbm->controller_regs + PSYCHO_PCIA_CTRL;
  534. } else {
  535. csr_reg = pbm->controller_regs + PSYCHO_PCIB_CTRL;
  536. }
  537. csr = psycho_read(csr_reg);
  538. csr_error_bits =
  539. csr & (PSYCHO_PCICTRL_SBH_ERR | PSYCHO_PCICTRL_SERR);
  540. if (csr_error_bits) {
  541. /* Clear the errors. */
  542. psycho_write(csr_reg, csr);
  543. /* Log 'em. */
  544. if (csr_error_bits & PSYCHO_PCICTRL_SBH_ERR)
  545. printk("%s: PCI streaming byte hole error asserted.\n",
  546. pbm->name);
  547. if (csr_error_bits & PSYCHO_PCICTRL_SERR)
  548. printk("%s: PCI SERR signal asserted.\n", pbm->name);
  549. ret = IRQ_HANDLED;
  550. }
  551. addr = psycho_pci_config_mkaddr(pbm, pbm->pci_first_busno,
  552. 0, PCI_STATUS);
  553. pci_config_read16(addr, &stat);
  554. if (stat & (PCI_STATUS_PARITY |
  555. PCI_STATUS_SIG_TARGET_ABORT |
  556. PCI_STATUS_REC_TARGET_ABORT |
  557. PCI_STATUS_REC_MASTER_ABORT |
  558. PCI_STATUS_SIG_SYSTEM_ERROR)) {
  559. printk("%s: PCI bus error, PCI_STATUS[%04x]\n",
  560. pbm->name, stat);
  561. pci_config_write16(addr, 0xffff);
  562. ret = IRQ_HANDLED;
  563. }
  564. return ret;
  565. }
  566. static irqreturn_t psycho_pcierr_intr(int irq, void *dev_id)
  567. {
  568. struct pci_pbm_info *pbm = dev_id;
  569. struct pci_controller_info *p = pbm->parent;
  570. unsigned long afsr_reg, afar_reg;
  571. unsigned long afsr, afar, error_bits;
  572. int is_pbm_a, reported;
  573. is_pbm_a = (pbm == &pbm->parent->pbm_A);
  574. if (is_pbm_a) {
  575. afsr_reg = p->pbm_A.controller_regs + PSYCHO_PCI_AFSR_A;
  576. afar_reg = p->pbm_A.controller_regs + PSYCHO_PCI_AFAR_A;
  577. } else {
  578. afsr_reg = p->pbm_A.controller_regs + PSYCHO_PCI_AFSR_B;
  579. afar_reg = p->pbm_A.controller_regs + PSYCHO_PCI_AFAR_B;
  580. }
  581. /* Latch error status. */
  582. afar = psycho_read(afar_reg);
  583. afsr = psycho_read(afsr_reg);
  584. /* Clear primary/secondary error status bits. */
  585. error_bits = afsr &
  586. (PSYCHO_PCIAFSR_PMA | PSYCHO_PCIAFSR_PTA |
  587. PSYCHO_PCIAFSR_PRTRY | PSYCHO_PCIAFSR_PPERR |
  588. PSYCHO_PCIAFSR_SMA | PSYCHO_PCIAFSR_STA |
  589. PSYCHO_PCIAFSR_SRTRY | PSYCHO_PCIAFSR_SPERR);
  590. if (!error_bits)
  591. return psycho_pcierr_intr_other(pbm, is_pbm_a);
  592. psycho_write(afsr_reg, error_bits);
  593. /* Log the error. */
  594. printk("%s: PCI Error, primary error type[%s]\n",
  595. pbm->name,
  596. (((error_bits & PSYCHO_PCIAFSR_PMA) ?
  597. "Master Abort" :
  598. ((error_bits & PSYCHO_PCIAFSR_PTA) ?
  599. "Target Abort" :
  600. ((error_bits & PSYCHO_PCIAFSR_PRTRY) ?
  601. "Excessive Retries" :
  602. ((error_bits & PSYCHO_PCIAFSR_PPERR) ?
  603. "Parity Error" : "???"))))));
  604. printk("%s: bytemask[%04lx] UPA_MID[%02lx] was_block(%d)\n",
  605. pbm->name,
  606. (afsr & PSYCHO_PCIAFSR_BMSK) >> 32UL,
  607. (afsr & PSYCHO_PCIAFSR_MID) >> 25UL,
  608. (afsr & PSYCHO_PCIAFSR_BLK) ? 1 : 0);
  609. printk("%s: PCI AFAR [%016lx]\n", pbm->name, afar);
  610. printk("%s: PCI Secondary errors [", pbm->name);
  611. reported = 0;
  612. if (afsr & PSYCHO_PCIAFSR_SMA) {
  613. reported++;
  614. printk("(Master Abort)");
  615. }
  616. if (afsr & PSYCHO_PCIAFSR_STA) {
  617. reported++;
  618. printk("(Target Abort)");
  619. }
  620. if (afsr & PSYCHO_PCIAFSR_SRTRY) {
  621. reported++;
  622. printk("(Excessive Retries)");
  623. }
  624. if (afsr & PSYCHO_PCIAFSR_SPERR) {
  625. reported++;
  626. printk("(Parity Error)");
  627. }
  628. if (!reported)
  629. printk("(none)");
  630. printk("]\n");
  631. /* For the error types shown, scan PBM's PCI bus for devices
  632. * which have logged that error type.
  633. */
  634. /* If we see a Target Abort, this could be the result of an
  635. * IOMMU translation error of some sort. It is extremely
  636. * useful to log this information as usually it indicates
  637. * a bug in the IOMMU support code or a PCI device driver.
  638. */
  639. if (error_bits & (PSYCHO_PCIAFSR_PTA | PSYCHO_PCIAFSR_STA)) {
  640. psycho_check_iommu_error(pbm, afsr, afar, PCI_ERR);
  641. pci_scan_for_target_abort(pbm, pbm->pci_bus);
  642. }
  643. if (error_bits & (PSYCHO_PCIAFSR_PMA | PSYCHO_PCIAFSR_SMA))
  644. pci_scan_for_master_abort(pbm, pbm->pci_bus);
  645. /* For excessive retries, PSYCHO/PBM will abort the device
  646. * and there is no way to specifically check for excessive
  647. * retries in the config space status registers. So what
  648. * we hope is that we'll catch it via the master/target
  649. * abort events.
  650. */
  651. if (error_bits & (PSYCHO_PCIAFSR_PPERR | PSYCHO_PCIAFSR_SPERR))
  652. pci_scan_for_parity_error(pbm, pbm->pci_bus);
  653. return IRQ_HANDLED;
  654. }
  655. /* XXX What about PowerFail/PowerManagement??? -DaveM */
  656. #define PSYCHO_ECC_CTRL 0x0020
  657. #define PSYCHO_ECCCTRL_EE 0x8000000000000000UL /* Enable ECC Checking */
  658. #define PSYCHO_ECCCTRL_UE 0x4000000000000000UL /* Enable UE Interrupts */
  659. #define PSYCHO_ECCCTRL_CE 0x2000000000000000UL /* Enable CE INterrupts */
  660. static void psycho_register_error_handlers(struct pci_pbm_info *pbm)
  661. {
  662. struct of_device *op = of_find_device_by_node(pbm->prom_node);
  663. unsigned long base = pbm->controller_regs;
  664. u64 tmp;
  665. int err;
  666. if (!op)
  667. return;
  668. /* Psycho interrupt property order is:
  669. * 0: PCIERR INO for this PBM
  670. * 1: UE ERR
  671. * 2: CE ERR
  672. * 3: POWER FAIL
  673. * 4: SPARE HARDWARE
  674. * 5: POWER MANAGEMENT
  675. */
  676. if (op->num_irqs < 6)
  677. return;
  678. /* We really mean to ignore the return result here. Two
  679. * PCI controller share the same interrupt numbers and
  680. * drive the same front-end hardware. Whichever of the
  681. * two get in here first will register the IRQ handler
  682. * the second will just error out since we do not pass in
  683. * IRQF_SHARED.
  684. */
  685. err = request_irq(op->irqs[1], psycho_ue_intr, IRQF_SHARED,
  686. "PSYCHO_UE", pbm);
  687. err = request_irq(op->irqs[2], psycho_ce_intr, IRQF_SHARED,
  688. "PSYCHO_CE", pbm);
  689. /* This one, however, ought not to fail. We can just warn
  690. * about it since the system can still operate properly even
  691. * if this fails.
  692. */
  693. err = request_irq(op->irqs[0], psycho_pcierr_intr, IRQF_SHARED,
  694. "PSYCHO_PCIERR", pbm);
  695. if (err)
  696. printk(KERN_WARNING "%s: Could not register PCIERR, "
  697. "err=%d\n", pbm->name, err);
  698. /* Enable UE and CE interrupts for controller. */
  699. psycho_write(base + PSYCHO_ECC_CTRL,
  700. (PSYCHO_ECCCTRL_EE |
  701. PSYCHO_ECCCTRL_UE |
  702. PSYCHO_ECCCTRL_CE));
  703. /* Enable PCI Error interrupts and clear error
  704. * bits for each PBM.
  705. */
  706. tmp = psycho_read(base + PSYCHO_PCIA_CTRL);
  707. tmp |= (PSYCHO_PCICTRL_SERR |
  708. PSYCHO_PCICTRL_SBH_ERR |
  709. PSYCHO_PCICTRL_EEN);
  710. tmp &= ~(PSYCHO_PCICTRL_SBH_INT);
  711. psycho_write(base + PSYCHO_PCIA_CTRL, tmp);
  712. tmp = psycho_read(base + PSYCHO_PCIB_CTRL);
  713. tmp |= (PSYCHO_PCICTRL_SERR |
  714. PSYCHO_PCICTRL_SBH_ERR |
  715. PSYCHO_PCICTRL_EEN);
  716. tmp &= ~(PSYCHO_PCICTRL_SBH_INT);
  717. psycho_write(base + PSYCHO_PCIB_CTRL, tmp);
  718. }
  719. /* PSYCHO boot time probing and initialization. */
  720. static void pbm_config_busmastering(struct pci_pbm_info *pbm)
  721. {
  722. u8 *addr;
  723. /* Set cache-line size to 64 bytes, this is actually
  724. * a nop but I do it for completeness.
  725. */
  726. addr = psycho_pci_config_mkaddr(pbm, pbm->pci_first_busno,
  727. 0, PCI_CACHE_LINE_SIZE);
  728. pci_config_write8(addr, 64 / sizeof(u32));
  729. /* Set PBM latency timer to 64 PCI clocks. */
  730. addr = psycho_pci_config_mkaddr(pbm, pbm->pci_first_busno,
  731. 0, PCI_LATENCY_TIMER);
  732. pci_config_write8(addr, 64);
  733. }
  734. static void __init psycho_scan_bus(struct pci_pbm_info *pbm)
  735. {
  736. pbm_config_busmastering(pbm);
  737. pbm->is_66mhz_capable = 0;
  738. pbm->pci_bus = pci_scan_one_pbm(pbm);
  739. /* After the PCI bus scan is complete, we can register
  740. * the error interrupt handlers.
  741. */
  742. psycho_register_error_handlers(pbm);
  743. }
  744. static int psycho_iommu_init(struct pci_pbm_info *pbm)
  745. {
  746. struct iommu *iommu = pbm->iommu;
  747. unsigned long i;
  748. u64 control;
  749. int err;
  750. /* Register addresses. */
  751. iommu->iommu_control = pbm->controller_regs + PSYCHO_IOMMU_CONTROL;
  752. iommu->iommu_tsbbase = pbm->controller_regs + PSYCHO_IOMMU_TSBBASE;
  753. iommu->iommu_flush = pbm->controller_regs + PSYCHO_IOMMU_FLUSH;
  754. iommu->iommu_tags = iommu->iommu_flush + (0xa580UL - 0x0210UL);
  755. /* PSYCHO's IOMMU lacks ctx flushing. */
  756. iommu->iommu_ctxflush = 0;
  757. /* We use the main control register of PSYCHO as the write
  758. * completion register.
  759. */
  760. iommu->write_complete_reg = pbm->controller_regs + PSYCHO_CONTROL;
  761. /*
  762. * Invalidate TLB Entries.
  763. */
  764. control = psycho_read(pbm->controller_regs + PSYCHO_IOMMU_CONTROL);
  765. control |= PSYCHO_IOMMU_CTRL_DENAB;
  766. psycho_write(pbm->controller_regs + PSYCHO_IOMMU_CONTROL, control);
  767. for(i = 0; i < 16; i++) {
  768. psycho_write(pbm->controller_regs + PSYCHO_IOMMU_TAG + (i * 8UL), 0);
  769. psycho_write(pbm->controller_regs + PSYCHO_IOMMU_DATA + (i * 8UL), 0);
  770. }
  771. /* Leave diag mode enabled for full-flushing done
  772. * in pci_iommu.c
  773. */
  774. err = iommu_table_init(iommu, IO_TSB_SIZE, 0xc0000000, 0xffffffff,
  775. pbm->numa_node);
  776. if (err)
  777. return err;
  778. psycho_write(pbm->controller_regs + PSYCHO_IOMMU_TSBBASE,
  779. __pa(iommu->page_table));
  780. control = psycho_read(pbm->controller_regs + PSYCHO_IOMMU_CONTROL);
  781. control &= ~(PSYCHO_IOMMU_CTRL_TSBSZ | PSYCHO_IOMMU_CTRL_TBWSZ);
  782. control |= (PSYCHO_IOMMU_TSBSZ_128K | PSYCHO_IOMMU_CTRL_ENAB);
  783. psycho_write(pbm->controller_regs + PSYCHO_IOMMU_CONTROL, control);
  784. /* If necessary, hook us up for starfire IRQ translations. */
  785. if (this_is_starfire)
  786. starfire_hookup(pbm->portid);
  787. return 0;
  788. }
  789. #define PSYCHO_IRQ_RETRY 0x1a00UL
  790. #define PSYCHO_PCIA_DIAG 0x2020UL
  791. #define PSYCHO_PCIB_DIAG 0x4020UL
  792. #define PSYCHO_PCIDIAG_RESV 0xffffffffffffff80UL /* Reserved */
  793. #define PSYCHO_PCIDIAG_DRETRY 0x0000000000000040UL /* Disable retry limit */
  794. #define PSYCHO_PCIDIAG_DISYNC 0x0000000000000020UL /* Disable DMA wr / irq sync */
  795. #define PSYCHO_PCIDIAG_DDWSYNC 0x0000000000000010UL /* Disable DMA wr / PIO rd sync */
  796. #define PSYCHO_PCIDIAG_IDDPAR 0x0000000000000008UL /* Invert DMA data parity */
  797. #define PSYCHO_PCIDIAG_IPDPAR 0x0000000000000004UL /* Invert PIO data parity */
  798. #define PSYCHO_PCIDIAG_IPAPAR 0x0000000000000002UL /* Invert PIO address parity */
  799. #define PSYCHO_PCIDIAG_LPBACK 0x0000000000000001UL /* Enable loopback mode */
  800. static void psycho_controller_hwinit(struct pci_pbm_info *pbm)
  801. {
  802. u64 tmp;
  803. psycho_write(pbm->controller_regs + PSYCHO_IRQ_RETRY, 5);
  804. /* Enable arbiter for all PCI slots. */
  805. tmp = psycho_read(pbm->controller_regs + PSYCHO_PCIA_CTRL);
  806. tmp |= PSYCHO_PCICTRL_AEN;
  807. psycho_write(pbm->controller_regs + PSYCHO_PCIA_CTRL, tmp);
  808. tmp = psycho_read(pbm->controller_regs + PSYCHO_PCIB_CTRL);
  809. tmp |= PSYCHO_PCICTRL_AEN;
  810. psycho_write(pbm->controller_regs + PSYCHO_PCIB_CTRL, tmp);
  811. /* Disable DMA write / PIO read synchronization on
  812. * both PCI bus segments.
  813. * [ U2P Erratum 1243770, STP2223BGA data sheet ]
  814. */
  815. tmp = psycho_read(pbm->controller_regs + PSYCHO_PCIA_DIAG);
  816. tmp |= PSYCHO_PCIDIAG_DDWSYNC;
  817. psycho_write(pbm->controller_regs + PSYCHO_PCIA_DIAG, tmp);
  818. tmp = psycho_read(pbm->controller_regs + PSYCHO_PCIB_DIAG);
  819. tmp |= PSYCHO_PCIDIAG_DDWSYNC;
  820. psycho_write(pbm->controller_regs + PSYCHO_PCIB_DIAG, tmp);
  821. }
  822. static void psycho_pbm_strbuf_init(struct pci_pbm_info *pbm,
  823. int is_pbm_a)
  824. {
  825. unsigned long base = pbm->controller_regs;
  826. u64 control;
  827. if (is_pbm_a) {
  828. pbm->stc.strbuf_control = base + PSYCHO_STRBUF_CONTROL_A;
  829. pbm->stc.strbuf_pflush = base + PSYCHO_STRBUF_FLUSH_A;
  830. pbm->stc.strbuf_fsync = base + PSYCHO_STRBUF_FSYNC_A;
  831. } else {
  832. pbm->stc.strbuf_control = base + PSYCHO_STRBUF_CONTROL_B;
  833. pbm->stc.strbuf_pflush = base + PSYCHO_STRBUF_FLUSH_B;
  834. pbm->stc.strbuf_fsync = base + PSYCHO_STRBUF_FSYNC_B;
  835. }
  836. /* PSYCHO's streaming buffer lacks ctx flushing. */
  837. pbm->stc.strbuf_ctxflush = 0;
  838. pbm->stc.strbuf_ctxmatch_base = 0;
  839. pbm->stc.strbuf_flushflag = (volatile unsigned long *)
  840. ((((unsigned long)&pbm->stc.__flushflag_buf[0])
  841. + 63UL)
  842. & ~63UL);
  843. pbm->stc.strbuf_flushflag_pa = (unsigned long)
  844. __pa(pbm->stc.strbuf_flushflag);
  845. /* Enable the streaming buffer. We have to be careful
  846. * just in case OBP left it with LRU locking enabled.
  847. *
  848. * It is possible to control if PBM will be rerun on
  849. * line misses. Currently I just retain whatever setting
  850. * OBP left us with. All checks so far show it having
  851. * a value of zero.
  852. */
  853. #undef PSYCHO_STRBUF_RERUN_ENABLE
  854. #undef PSYCHO_STRBUF_RERUN_DISABLE
  855. control = psycho_read(pbm->stc.strbuf_control);
  856. control |= PSYCHO_STRBUF_CTRL_ENAB;
  857. control &= ~(PSYCHO_STRBUF_CTRL_LENAB | PSYCHO_STRBUF_CTRL_LPTR);
  858. #ifdef PSYCHO_STRBUF_RERUN_ENABLE
  859. control &= ~(PSYCHO_STRBUF_CTRL_RRDIS);
  860. #else
  861. #ifdef PSYCHO_STRBUF_RERUN_DISABLE
  862. control |= PSYCHO_STRBUF_CTRL_RRDIS;
  863. #endif
  864. #endif
  865. psycho_write(pbm->stc.strbuf_control, control);
  866. pbm->stc.strbuf_enabled = 1;
  867. }
  868. #define PSYCHO_IOSPACE_A 0x002000000UL
  869. #define PSYCHO_IOSPACE_B 0x002010000UL
  870. #define PSYCHO_IOSPACE_SIZE 0x00000ffffUL
  871. #define PSYCHO_MEMSPACE_A 0x100000000UL
  872. #define PSYCHO_MEMSPACE_B 0x180000000UL
  873. #define PSYCHO_MEMSPACE_SIZE 0x07fffffffUL
  874. static void __init psycho_pbm_init(struct pci_controller_info *p,
  875. struct device_node *dp, int is_pbm_a)
  876. {
  877. struct property *prop;
  878. struct pci_pbm_info *pbm;
  879. if (is_pbm_a)
  880. pbm = &p->pbm_A;
  881. else
  882. pbm = &p->pbm_B;
  883. pbm->next = pci_pbm_root;
  884. pci_pbm_root = pbm;
  885. pbm->numa_node = -1;
  886. pbm->scan_bus = psycho_scan_bus;
  887. pbm->pci_ops = &sun4u_pci_ops;
  888. pbm->config_space_reg_bits = 8;
  889. pbm->index = pci_num_pbms++;
  890. pbm->chip_type = PBM_CHIP_TYPE_PSYCHO;
  891. pbm->chip_version = 0;
  892. prop = of_find_property(dp, "version#", NULL);
  893. if (prop)
  894. pbm->chip_version = *(int *) prop->value;
  895. pbm->chip_revision = 0;
  896. prop = of_find_property(dp, "module-revision#", NULL);
  897. if (prop)
  898. pbm->chip_revision = *(int *) prop->value;
  899. pbm->parent = p;
  900. pbm->prom_node = dp;
  901. pbm->name = dp->full_name;
  902. printk("%s: PSYCHO PCI Bus Module ver[%x:%x]\n",
  903. pbm->name,
  904. pbm->chip_version, pbm->chip_revision);
  905. pci_determine_mem_io_space(pbm);
  906. pci_get_pbm_props(pbm);
  907. psycho_pbm_strbuf_init(pbm, is_pbm_a);
  908. }
  909. #define PSYCHO_CONFIGSPACE 0x001000000UL
  910. void __init psycho_init(struct device_node *dp, char *model_name)
  911. {
  912. struct linux_prom64_registers *pr_regs;
  913. struct pci_controller_info *p;
  914. struct pci_pbm_info *pbm;
  915. struct iommu *iommu;
  916. struct property *prop;
  917. u32 upa_portid;
  918. int is_pbm_a;
  919. upa_portid = 0xff;
  920. prop = of_find_property(dp, "upa-portid", NULL);
  921. if (prop)
  922. upa_portid = *(u32 *) prop->value;
  923. for (pbm = pci_pbm_root; pbm; pbm = pbm->next) {
  924. struct pci_controller_info *p = pbm->parent;
  925. if (p->pbm_A.portid == upa_portid) {
  926. is_pbm_a = (p->pbm_A.prom_node == NULL);
  927. psycho_pbm_init(p, dp, is_pbm_a);
  928. return;
  929. }
  930. }
  931. p = kzalloc(sizeof(struct pci_controller_info), GFP_ATOMIC);
  932. if (!p)
  933. goto fatal_memory_error;
  934. iommu = kzalloc(sizeof(struct iommu), GFP_ATOMIC);
  935. if (!iommu)
  936. goto fatal_memory_error;
  937. p->pbm_A.iommu = p->pbm_B.iommu = iommu;
  938. p->pbm_A.portid = upa_portid;
  939. p->pbm_B.portid = upa_portid;
  940. prop = of_find_property(dp, "reg", NULL);
  941. pr_regs = prop->value;
  942. p->pbm_A.controller_regs = pr_regs[2].phys_addr;
  943. p->pbm_B.controller_regs = pr_regs[2].phys_addr;
  944. p->pbm_A.config_space = p->pbm_B.config_space =
  945. (pr_regs[2].phys_addr + PSYCHO_CONFIGSPACE);
  946. psycho_controller_hwinit(&p->pbm_A);
  947. if (psycho_iommu_init(&p->pbm_A))
  948. goto fatal_memory_error;
  949. is_pbm_a = ((pr_regs[0].phys_addr & 0x6000) == 0x2000);
  950. psycho_pbm_init(p, dp, is_pbm_a);
  951. return;
  952. fatal_memory_error:
  953. prom_printf("PSYCHO: Fatal memory allocation error.\n");
  954. prom_halt();
  955. }