pci_psycho.c 39 KB

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