pci_psycho.c 42 KB

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