pci_psycho.c 43 KB

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