pci_schizo.c 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651
  1. /* pci_schizo.c: SCHIZO/TOMATILLO specific PCI controller support.
  2. *
  3. * Copyright (C) 2001, 2002, 2003, 2007 David S. Miller (davem@davemloft.net)
  4. */
  5. #include <linux/kernel.h>
  6. #include <linux/types.h>
  7. #include <linux/pci.h>
  8. #include <linux/init.h>
  9. #include <linux/slab.h>
  10. #include <linux/interrupt.h>
  11. #include <asm/pbm.h>
  12. #include <asm/iommu.h>
  13. #include <asm/irq.h>
  14. #include <asm/upa.h>
  15. #include <asm/pstate.h>
  16. #include <asm/prom.h>
  17. #include "pci_impl.h"
  18. #include "iommu_common.h"
  19. /* All SCHIZO registers are 64-bits. The following accessor
  20. * routines are how they are accessed. The REG parameter
  21. * is a physical address.
  22. */
  23. #define schizo_read(__reg) \
  24. ({ u64 __ret; \
  25. __asm__ __volatile__("ldxa [%1] %2, %0" \
  26. : "=r" (__ret) \
  27. : "r" (__reg), "i" (ASI_PHYS_BYPASS_EC_E) \
  28. : "memory"); \
  29. __ret; \
  30. })
  31. #define schizo_write(__reg, __val) \
  32. __asm__ __volatile__("stxa %0, [%1] %2" \
  33. : /* no outputs */ \
  34. : "r" (__val), "r" (__reg), \
  35. "i" (ASI_PHYS_BYPASS_EC_E) \
  36. : "memory")
  37. /* This is a convention that at least Excalibur and Merlin
  38. * follow. I suppose the SCHIZO used in Starcat and friends
  39. * will do similar.
  40. *
  41. * The only way I could see this changing is if the newlink
  42. * block requires more space in Schizo's address space than
  43. * they predicted, thus requiring an address space reorg when
  44. * the newer Schizo is taped out.
  45. */
  46. /* Streaming buffer control register. */
  47. #define SCHIZO_STRBUF_CTRL_LPTR 0x00000000000000f0UL /* LRU Lock Pointer */
  48. #define SCHIZO_STRBUF_CTRL_LENAB 0x0000000000000008UL /* LRU Lock Enable */
  49. #define SCHIZO_STRBUF_CTRL_RRDIS 0x0000000000000004UL /* Rerun Disable */
  50. #define SCHIZO_STRBUF_CTRL_DENAB 0x0000000000000002UL /* Diagnostic Mode Enable */
  51. #define SCHIZO_STRBUF_CTRL_ENAB 0x0000000000000001UL /* Streaming Buffer Enable */
  52. /* IOMMU control register. */
  53. #define SCHIZO_IOMMU_CTRL_RESV 0xfffffffff9000000UL /* Reserved */
  54. #define SCHIZO_IOMMU_CTRL_XLTESTAT 0x0000000006000000UL /* Translation Error Status */
  55. #define SCHIZO_IOMMU_CTRL_XLTEERR 0x0000000001000000UL /* Translation Error encountered */
  56. #define SCHIZO_IOMMU_CTRL_LCKEN 0x0000000000800000UL /* Enable translation locking */
  57. #define SCHIZO_IOMMU_CTRL_LCKPTR 0x0000000000780000UL /* Translation lock pointer */
  58. #define SCHIZO_IOMMU_CTRL_TSBSZ 0x0000000000070000UL /* TSB Size */
  59. #define SCHIZO_IOMMU_TSBSZ_1K 0x0000000000000000UL /* TSB Table 1024 8-byte entries */
  60. #define SCHIZO_IOMMU_TSBSZ_2K 0x0000000000010000UL /* TSB Table 2048 8-byte entries */
  61. #define SCHIZO_IOMMU_TSBSZ_4K 0x0000000000020000UL /* TSB Table 4096 8-byte entries */
  62. #define SCHIZO_IOMMU_TSBSZ_8K 0x0000000000030000UL /* TSB Table 8192 8-byte entries */
  63. #define SCHIZO_IOMMU_TSBSZ_16K 0x0000000000040000UL /* TSB Table 16k 8-byte entries */
  64. #define SCHIZO_IOMMU_TSBSZ_32K 0x0000000000050000UL /* TSB Table 32k 8-byte entries */
  65. #define SCHIZO_IOMMU_TSBSZ_64K 0x0000000000060000UL /* TSB Table 64k 8-byte entries */
  66. #define SCHIZO_IOMMU_TSBSZ_128K 0x0000000000070000UL /* TSB Table 128k 8-byte entries */
  67. #define SCHIZO_IOMMU_CTRL_RESV2 0x000000000000fff8UL /* Reserved */
  68. #define SCHIZO_IOMMU_CTRL_TBWSZ 0x0000000000000004UL /* Assumed page size, 0=8k 1=64k */
  69. #define SCHIZO_IOMMU_CTRL_DENAB 0x0000000000000002UL /* Diagnostic mode enable */
  70. #define SCHIZO_IOMMU_CTRL_ENAB 0x0000000000000001UL /* IOMMU Enable */
  71. /* Schizo config space address format is nearly identical to
  72. * that of PSYCHO:
  73. *
  74. * 32 24 23 16 15 11 10 8 7 2 1 0
  75. * ---------------------------------------------------------
  76. * |0 0 0 0 0 0 0 0 0| bus | device | function | reg | 0 0 |
  77. * ---------------------------------------------------------
  78. */
  79. #define SCHIZO_CONFIG_BASE(PBM) ((PBM)->config_space)
  80. #define SCHIZO_CONFIG_ENCODE(BUS, DEVFN, REG) \
  81. (((unsigned long)(BUS) << 16) | \
  82. ((unsigned long)(DEVFN) << 8) | \
  83. ((unsigned long)(REG)))
  84. static void *schizo_pci_config_mkaddr(struct pci_pbm_info *pbm,
  85. unsigned char bus,
  86. unsigned int devfn,
  87. int where)
  88. {
  89. if (!pbm)
  90. return NULL;
  91. bus -= pbm->pci_first_busno;
  92. return (void *)
  93. (SCHIZO_CONFIG_BASE(pbm) |
  94. SCHIZO_CONFIG_ENCODE(bus, devfn, where));
  95. }
  96. /* Just make sure the bus number is in range. */
  97. static int schizo_out_of_range(struct pci_pbm_info *pbm,
  98. unsigned char bus,
  99. unsigned char devfn)
  100. {
  101. if (bus < pbm->pci_first_busno ||
  102. bus > pbm->pci_last_busno)
  103. return 1;
  104. return 0;
  105. }
  106. /* SCHIZO PCI configuration space accessors. */
  107. static int schizo_read_pci_cfg(struct pci_bus *bus_dev, unsigned int devfn,
  108. int where, int size, u32 *value)
  109. {
  110. struct pci_pbm_info *pbm = bus_dev->sysdata;
  111. unsigned char bus = bus_dev->number;
  112. u32 *addr;
  113. u16 tmp16;
  114. u8 tmp8;
  115. if (bus_dev == pbm->pci_bus && devfn == 0x00)
  116. return pci_host_bridge_read_pci_cfg(bus_dev, devfn, where,
  117. size, value);
  118. switch (size) {
  119. case 1:
  120. *value = 0xff;
  121. break;
  122. case 2:
  123. *value = 0xffff;
  124. break;
  125. case 4:
  126. *value = 0xffffffff;
  127. break;
  128. }
  129. addr = schizo_pci_config_mkaddr(pbm, bus, devfn, where);
  130. if (!addr)
  131. return PCIBIOS_SUCCESSFUL;
  132. if (schizo_out_of_range(pbm, bus, devfn))
  133. return PCIBIOS_SUCCESSFUL;
  134. switch (size) {
  135. case 1:
  136. pci_config_read8((u8 *)addr, &tmp8);
  137. *value = tmp8;
  138. break;
  139. case 2:
  140. if (where & 0x01) {
  141. printk("pci_read_config_word: misaligned reg [%x]\n",
  142. where);
  143. return PCIBIOS_SUCCESSFUL;
  144. }
  145. pci_config_read16((u16 *)addr, &tmp16);
  146. *value = tmp16;
  147. break;
  148. case 4:
  149. if (where & 0x03) {
  150. printk("pci_read_config_dword: misaligned reg [%x]\n",
  151. where);
  152. return PCIBIOS_SUCCESSFUL;
  153. }
  154. pci_config_read32(addr, value);
  155. break;
  156. }
  157. return PCIBIOS_SUCCESSFUL;
  158. }
  159. static int schizo_write_pci_cfg(struct pci_bus *bus_dev, unsigned int devfn,
  160. int where, int size, u32 value)
  161. {
  162. struct pci_pbm_info *pbm = bus_dev->sysdata;
  163. unsigned char bus = bus_dev->number;
  164. u32 *addr;
  165. if (bus_dev == pbm->pci_bus && devfn == 0x00)
  166. return pci_host_bridge_write_pci_cfg(bus_dev, devfn, where,
  167. size, value);
  168. addr = schizo_pci_config_mkaddr(pbm, bus, devfn, where);
  169. if (!addr)
  170. return PCIBIOS_SUCCESSFUL;
  171. if (schizo_out_of_range(pbm, bus, devfn))
  172. return PCIBIOS_SUCCESSFUL;
  173. switch (size) {
  174. case 1:
  175. pci_config_write8((u8 *)addr, value);
  176. break;
  177. case 2:
  178. if (where & 0x01) {
  179. printk("pci_write_config_word: misaligned reg [%x]\n",
  180. where);
  181. return PCIBIOS_SUCCESSFUL;
  182. }
  183. pci_config_write16((u16 *)addr, value);
  184. break;
  185. case 4:
  186. if (where & 0x03) {
  187. printk("pci_write_config_dword: misaligned reg [%x]\n",
  188. where);
  189. return PCIBIOS_SUCCESSFUL;
  190. }
  191. pci_config_write32(addr, value);
  192. }
  193. return PCIBIOS_SUCCESSFUL;
  194. }
  195. static struct pci_ops schizo_ops = {
  196. .read = schizo_read_pci_cfg,
  197. .write = schizo_write_pci_cfg,
  198. };
  199. /* SCHIZO error handling support. */
  200. enum schizo_error_type {
  201. UE_ERR, CE_ERR, PCI_ERR, SAFARI_ERR
  202. };
  203. static DEFINE_SPINLOCK(stc_buf_lock);
  204. static unsigned long stc_error_buf[128];
  205. static unsigned long stc_tag_buf[16];
  206. static unsigned long stc_line_buf[16];
  207. #define SCHIZO_UE_INO 0x30 /* Uncorrectable ECC error */
  208. #define SCHIZO_CE_INO 0x31 /* Correctable ECC error */
  209. #define SCHIZO_PCIERR_A_INO 0x32 /* PBM A PCI bus error */
  210. #define SCHIZO_PCIERR_B_INO 0x33 /* PBM B PCI bus error */
  211. #define SCHIZO_SERR_INO 0x34 /* Safari interface error */
  212. struct pci_pbm_info *pbm_for_ino(struct pci_controller_info *p, u32 ino)
  213. {
  214. ino &= IMAP_INO;
  215. if (p->pbm_A.ino_bitmap & (1UL << ino))
  216. return &p->pbm_A;
  217. if (p->pbm_B.ino_bitmap & (1UL << ino))
  218. return &p->pbm_B;
  219. printk("PCI%d: No ino_bitmap entry for ino[%x], bitmaps "
  220. "PBM_A[%016lx] PBM_B[%016lx]",
  221. p->index, ino,
  222. p->pbm_A.ino_bitmap,
  223. p->pbm_B.ino_bitmap);
  224. printk("PCI%d: Using PBM_A, report this problem immediately.\n",
  225. p->index);
  226. return &p->pbm_A;
  227. }
  228. #define SCHIZO_STC_ERR 0xb800UL /* --> 0xba00 */
  229. #define SCHIZO_STC_TAG 0xba00UL /* --> 0xba80 */
  230. #define SCHIZO_STC_LINE 0xbb00UL /* --> 0xbb80 */
  231. #define SCHIZO_STCERR_WRITE 0x2UL
  232. #define SCHIZO_STCERR_READ 0x1UL
  233. #define SCHIZO_STCTAG_PPN 0x3fffffff00000000UL
  234. #define SCHIZO_STCTAG_VPN 0x00000000ffffe000UL
  235. #define SCHIZO_STCTAG_VALID 0x8000000000000000UL
  236. #define SCHIZO_STCTAG_READ 0x4000000000000000UL
  237. #define SCHIZO_STCLINE_LINDX 0x0000000007800000UL
  238. #define SCHIZO_STCLINE_SPTR 0x000000000007e000UL
  239. #define SCHIZO_STCLINE_LADDR 0x0000000000001fc0UL
  240. #define SCHIZO_STCLINE_EPTR 0x000000000000003fUL
  241. #define SCHIZO_STCLINE_VALID 0x0000000000600000UL
  242. #define SCHIZO_STCLINE_FOFN 0x0000000000180000UL
  243. static void __schizo_check_stc_error_pbm(struct pci_pbm_info *pbm,
  244. enum schizo_error_type type)
  245. {
  246. struct strbuf *strbuf = &pbm->stc;
  247. unsigned long regbase = pbm->pbm_regs;
  248. unsigned long err_base, tag_base, line_base;
  249. u64 control;
  250. int i;
  251. err_base = regbase + SCHIZO_STC_ERR;
  252. tag_base = regbase + SCHIZO_STC_TAG;
  253. line_base = regbase + SCHIZO_STC_LINE;
  254. spin_lock(&stc_buf_lock);
  255. /* This is __REALLY__ dangerous. When we put the
  256. * streaming buffer into diagnostic mode to probe
  257. * it's tags and error status, we _must_ clear all
  258. * of the line tag valid bits before re-enabling
  259. * the streaming buffer. If any dirty data lives
  260. * in the STC when we do this, we will end up
  261. * invalidating it before it has a chance to reach
  262. * main memory.
  263. */
  264. control = schizo_read(strbuf->strbuf_control);
  265. schizo_write(strbuf->strbuf_control,
  266. (control | SCHIZO_STRBUF_CTRL_DENAB));
  267. for (i = 0; i < 128; i++) {
  268. unsigned long val;
  269. val = schizo_read(err_base + (i * 8UL));
  270. schizo_write(err_base + (i * 8UL), 0UL);
  271. stc_error_buf[i] = val;
  272. }
  273. for (i = 0; i < 16; i++) {
  274. stc_tag_buf[i] = schizo_read(tag_base + (i * 8UL));
  275. stc_line_buf[i] = schizo_read(line_base + (i * 8UL));
  276. schizo_write(tag_base + (i * 8UL), 0UL);
  277. schizo_write(line_base + (i * 8UL), 0UL);
  278. }
  279. /* OK, state is logged, exit diagnostic mode. */
  280. schizo_write(strbuf->strbuf_control, control);
  281. for (i = 0; i < 16; i++) {
  282. int j, saw_error, first, last;
  283. saw_error = 0;
  284. first = i * 8;
  285. last = first + 8;
  286. for (j = first; j < last; j++) {
  287. unsigned long errval = stc_error_buf[j];
  288. if (errval != 0) {
  289. saw_error++;
  290. printk("%s: STC_ERR(%d)[wr(%d)rd(%d)]\n",
  291. pbm->name,
  292. j,
  293. (errval & SCHIZO_STCERR_WRITE) ? 1 : 0,
  294. (errval & SCHIZO_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("%s: STC_TAG(%d)[PA(%016lx)VA(%08lx)V(%d)R(%d)]\n",
  301. pbm->name,
  302. i,
  303. ((tagval & SCHIZO_STCTAG_PPN) >> 19UL),
  304. (tagval & SCHIZO_STCTAG_VPN),
  305. ((tagval & SCHIZO_STCTAG_VALID) ? 1 : 0),
  306. ((tagval & SCHIZO_STCTAG_READ) ? 1 : 0));
  307. /* XXX Should spit out per-bank error information... -DaveM */
  308. printk("%s: STC_LINE(%d)[LIDX(%lx)SP(%lx)LADDR(%lx)EP(%lx)"
  309. "V(%d)FOFN(%d)]\n",
  310. pbm->name,
  311. i,
  312. ((lineval & SCHIZO_STCLINE_LINDX) >> 23UL),
  313. ((lineval & SCHIZO_STCLINE_SPTR) >> 13UL),
  314. ((lineval & SCHIZO_STCLINE_LADDR) >> 6UL),
  315. ((lineval & SCHIZO_STCLINE_EPTR) >> 0UL),
  316. ((lineval & SCHIZO_STCLINE_VALID) ? 1 : 0),
  317. ((lineval & SCHIZO_STCLINE_FOFN) ? 1 : 0));
  318. }
  319. }
  320. spin_unlock(&stc_buf_lock);
  321. }
  322. /* IOMMU is per-PBM in Schizo, so interrogate both for anonymous
  323. * controller level errors.
  324. */
  325. #define SCHIZO_IOMMU_TAG 0xa580UL
  326. #define SCHIZO_IOMMU_DATA 0xa600UL
  327. #define SCHIZO_IOMMU_TAG_CTXT 0x0000001ffe000000UL
  328. #define SCHIZO_IOMMU_TAG_ERRSTS 0x0000000001800000UL
  329. #define SCHIZO_IOMMU_TAG_ERR 0x0000000000400000UL
  330. #define SCHIZO_IOMMU_TAG_WRITE 0x0000000000200000UL
  331. #define SCHIZO_IOMMU_TAG_STREAM 0x0000000000100000UL
  332. #define SCHIZO_IOMMU_TAG_SIZE 0x0000000000080000UL
  333. #define SCHIZO_IOMMU_TAG_VPAGE 0x000000000007ffffUL
  334. #define SCHIZO_IOMMU_DATA_VALID 0x0000000100000000UL
  335. #define SCHIZO_IOMMU_DATA_CACHE 0x0000000040000000UL
  336. #define SCHIZO_IOMMU_DATA_PPAGE 0x000000003fffffffUL
  337. static void schizo_check_iommu_error_pbm(struct pci_pbm_info *pbm,
  338. enum schizo_error_type type)
  339. {
  340. struct iommu *iommu = pbm->iommu;
  341. unsigned long iommu_tag[16];
  342. unsigned long iommu_data[16];
  343. unsigned long flags;
  344. u64 control;
  345. int i;
  346. spin_lock_irqsave(&iommu->lock, flags);
  347. control = schizo_read(iommu->iommu_control);
  348. if (control & SCHIZO_IOMMU_CTRL_XLTEERR) {
  349. unsigned long base;
  350. char *type_string;
  351. /* Clear the error encountered bit. */
  352. control &= ~SCHIZO_IOMMU_CTRL_XLTEERR;
  353. schizo_write(iommu->iommu_control, control);
  354. switch((control & SCHIZO_IOMMU_CTRL_XLTESTAT) >> 25UL) {
  355. case 0:
  356. type_string = "Protection Error";
  357. break;
  358. case 1:
  359. type_string = "Invalid Error";
  360. break;
  361. case 2:
  362. type_string = "TimeOut Error";
  363. break;
  364. case 3:
  365. default:
  366. type_string = "ECC Error";
  367. break;
  368. };
  369. printk("%s: IOMMU Error, type[%s]\n",
  370. pbm->name, type_string);
  371. /* Put the IOMMU into diagnostic mode and probe
  372. * it's TLB for entries with error status.
  373. *
  374. * It is very possible for another DVMA to occur
  375. * while we do this probe, and corrupt the system
  376. * further. But we are so screwed at this point
  377. * that we are likely to crash hard anyways, so
  378. * get as much diagnostic information to the
  379. * console as we can.
  380. */
  381. schizo_write(iommu->iommu_control,
  382. control | SCHIZO_IOMMU_CTRL_DENAB);
  383. base = pbm->pbm_regs;
  384. for (i = 0; i < 16; i++) {
  385. iommu_tag[i] =
  386. schizo_read(base + SCHIZO_IOMMU_TAG + (i * 8UL));
  387. iommu_data[i] =
  388. schizo_read(base + SCHIZO_IOMMU_DATA + (i * 8UL));
  389. /* Now clear out the entry. */
  390. schizo_write(base + SCHIZO_IOMMU_TAG + (i * 8UL), 0);
  391. schizo_write(base + SCHIZO_IOMMU_DATA + (i * 8UL), 0);
  392. }
  393. /* Leave diagnostic mode. */
  394. schizo_write(iommu->iommu_control, control);
  395. for (i = 0; i < 16; i++) {
  396. unsigned long tag, data;
  397. tag = iommu_tag[i];
  398. if (!(tag & SCHIZO_IOMMU_TAG_ERR))
  399. continue;
  400. data = iommu_data[i];
  401. switch((tag & SCHIZO_IOMMU_TAG_ERRSTS) >> 23UL) {
  402. case 0:
  403. type_string = "Protection Error";
  404. break;
  405. case 1:
  406. type_string = "Invalid Error";
  407. break;
  408. case 2:
  409. type_string = "TimeOut Error";
  410. break;
  411. case 3:
  412. default:
  413. type_string = "ECC Error";
  414. break;
  415. };
  416. printk("%s: IOMMU TAG(%d)[error(%s) ctx(%x) wr(%d) str(%d) "
  417. "sz(%dK) vpg(%08lx)]\n",
  418. pbm->name, i, type_string,
  419. (int)((tag & SCHIZO_IOMMU_TAG_CTXT) >> 25UL),
  420. ((tag & SCHIZO_IOMMU_TAG_WRITE) ? 1 : 0),
  421. ((tag & SCHIZO_IOMMU_TAG_STREAM) ? 1 : 0),
  422. ((tag & SCHIZO_IOMMU_TAG_SIZE) ? 64 : 8),
  423. (tag & SCHIZO_IOMMU_TAG_VPAGE) << IOMMU_PAGE_SHIFT);
  424. printk("%s: IOMMU DATA(%d)[valid(%d) cache(%d) ppg(%016lx)]\n",
  425. pbm->name, i,
  426. ((data & SCHIZO_IOMMU_DATA_VALID) ? 1 : 0),
  427. ((data & SCHIZO_IOMMU_DATA_CACHE) ? 1 : 0),
  428. (data & SCHIZO_IOMMU_DATA_PPAGE) << IOMMU_PAGE_SHIFT);
  429. }
  430. }
  431. if (pbm->stc.strbuf_enabled)
  432. __schizo_check_stc_error_pbm(pbm, type);
  433. spin_unlock_irqrestore(&iommu->lock, flags);
  434. }
  435. static void schizo_check_iommu_error(struct pci_controller_info *p,
  436. enum schizo_error_type type)
  437. {
  438. schizo_check_iommu_error_pbm(&p->pbm_A, type);
  439. schizo_check_iommu_error_pbm(&p->pbm_B, type);
  440. }
  441. /* Uncorrectable ECC error status gathering. */
  442. #define SCHIZO_UE_AFSR 0x10030UL
  443. #define SCHIZO_UE_AFAR 0x10038UL
  444. #define SCHIZO_UEAFSR_PPIO 0x8000000000000000UL /* Safari */
  445. #define SCHIZO_UEAFSR_PDRD 0x4000000000000000UL /* Safari/Tomatillo */
  446. #define SCHIZO_UEAFSR_PDWR 0x2000000000000000UL /* Safari */
  447. #define SCHIZO_UEAFSR_SPIO 0x1000000000000000UL /* Safari */
  448. #define SCHIZO_UEAFSR_SDMA 0x0800000000000000UL /* Safari/Tomatillo */
  449. #define SCHIZO_UEAFSR_ERRPNDG 0x0300000000000000UL /* Safari */
  450. #define SCHIZO_UEAFSR_BMSK 0x000003ff00000000UL /* Safari */
  451. #define SCHIZO_UEAFSR_QOFF 0x00000000c0000000UL /* Safari/Tomatillo */
  452. #define SCHIZO_UEAFSR_AID 0x000000001f000000UL /* Safari/Tomatillo */
  453. #define SCHIZO_UEAFSR_PARTIAL 0x0000000000800000UL /* Safari */
  454. #define SCHIZO_UEAFSR_OWNEDIN 0x0000000000400000UL /* Safari */
  455. #define SCHIZO_UEAFSR_MTAGSYND 0x00000000000f0000UL /* Safari */
  456. #define SCHIZO_UEAFSR_MTAG 0x000000000000e000UL /* Safari */
  457. #define SCHIZO_UEAFSR_ECCSYND 0x00000000000001ffUL /* Safari */
  458. static irqreturn_t schizo_ue_intr(int irq, void *dev_id)
  459. {
  460. struct pci_controller_info *p = dev_id;
  461. unsigned long afsr_reg = p->pbm_B.controller_regs + SCHIZO_UE_AFSR;
  462. unsigned long afar_reg = p->pbm_B.controller_regs + SCHIZO_UE_AFAR;
  463. unsigned long afsr, afar, error_bits;
  464. int reported, limit;
  465. /* Latch uncorrectable error status. */
  466. afar = schizo_read(afar_reg);
  467. /* If either of the error pending bits are set in the
  468. * AFSR, the error status is being actively updated by
  469. * the hardware and we must re-read to get a clean value.
  470. */
  471. limit = 1000;
  472. do {
  473. afsr = schizo_read(afsr_reg);
  474. } while ((afsr & SCHIZO_UEAFSR_ERRPNDG) != 0 && --limit);
  475. /* Clear the primary/secondary error status bits. */
  476. error_bits = afsr &
  477. (SCHIZO_UEAFSR_PPIO | SCHIZO_UEAFSR_PDRD | SCHIZO_UEAFSR_PDWR |
  478. SCHIZO_UEAFSR_SPIO | SCHIZO_UEAFSR_SDMA);
  479. if (!error_bits)
  480. return IRQ_NONE;
  481. schizo_write(afsr_reg, error_bits);
  482. /* Log the error. */
  483. printk("PCI%d: Uncorrectable Error, primary error type[%s]\n",
  484. p->index,
  485. (((error_bits & SCHIZO_UEAFSR_PPIO) ?
  486. "PIO" :
  487. ((error_bits & SCHIZO_UEAFSR_PDRD) ?
  488. "DMA Read" :
  489. ((error_bits & SCHIZO_UEAFSR_PDWR) ?
  490. "DMA Write" : "???")))));
  491. printk("PCI%d: bytemask[%04lx] qword_offset[%lx] SAFARI_AID[%02lx]\n",
  492. p->index,
  493. (afsr & SCHIZO_UEAFSR_BMSK) >> 32UL,
  494. (afsr & SCHIZO_UEAFSR_QOFF) >> 30UL,
  495. (afsr & SCHIZO_UEAFSR_AID) >> 24UL);
  496. printk("PCI%d: partial[%d] owned_in[%d] mtag[%lx] mtag_synd[%lx] ecc_sync[%lx]\n",
  497. p->index,
  498. (afsr & SCHIZO_UEAFSR_PARTIAL) ? 1 : 0,
  499. (afsr & SCHIZO_UEAFSR_OWNEDIN) ? 1 : 0,
  500. (afsr & SCHIZO_UEAFSR_MTAG) >> 13UL,
  501. (afsr & SCHIZO_UEAFSR_MTAGSYND) >> 16UL,
  502. (afsr & SCHIZO_UEAFSR_ECCSYND) >> 0UL);
  503. printk("PCI%d: UE AFAR [%016lx]\n", p->index, afar);
  504. printk("PCI%d: UE Secondary errors [", p->index);
  505. reported = 0;
  506. if (afsr & SCHIZO_UEAFSR_SPIO) {
  507. reported++;
  508. printk("(PIO)");
  509. }
  510. if (afsr & SCHIZO_UEAFSR_SDMA) {
  511. reported++;
  512. printk("(DMA)");
  513. }
  514. if (!reported)
  515. printk("(none)");
  516. printk("]\n");
  517. /* Interrogate IOMMU for error status. */
  518. schizo_check_iommu_error(p, UE_ERR);
  519. return IRQ_HANDLED;
  520. }
  521. #define SCHIZO_CE_AFSR 0x10040UL
  522. #define SCHIZO_CE_AFAR 0x10048UL
  523. #define SCHIZO_CEAFSR_PPIO 0x8000000000000000UL
  524. #define SCHIZO_CEAFSR_PDRD 0x4000000000000000UL
  525. #define SCHIZO_CEAFSR_PDWR 0x2000000000000000UL
  526. #define SCHIZO_CEAFSR_SPIO 0x1000000000000000UL
  527. #define SCHIZO_CEAFSR_SDMA 0x0800000000000000UL
  528. #define SCHIZO_CEAFSR_ERRPNDG 0x0300000000000000UL
  529. #define SCHIZO_CEAFSR_BMSK 0x000003ff00000000UL
  530. #define SCHIZO_CEAFSR_QOFF 0x00000000c0000000UL
  531. #define SCHIZO_CEAFSR_AID 0x000000001f000000UL
  532. #define SCHIZO_CEAFSR_PARTIAL 0x0000000000800000UL
  533. #define SCHIZO_CEAFSR_OWNEDIN 0x0000000000400000UL
  534. #define SCHIZO_CEAFSR_MTAGSYND 0x00000000000f0000UL
  535. #define SCHIZO_CEAFSR_MTAG 0x000000000000e000UL
  536. #define SCHIZO_CEAFSR_ECCSYND 0x00000000000001ffUL
  537. static irqreturn_t schizo_ce_intr(int irq, void *dev_id)
  538. {
  539. struct pci_controller_info *p = dev_id;
  540. unsigned long afsr_reg = p->pbm_B.controller_regs + SCHIZO_CE_AFSR;
  541. unsigned long afar_reg = p->pbm_B.controller_regs + SCHIZO_CE_AFAR;
  542. unsigned long afsr, afar, error_bits;
  543. int reported, limit;
  544. /* Latch error status. */
  545. afar = schizo_read(afar_reg);
  546. /* If either of the error pending bits are set in the
  547. * AFSR, the error status is being actively updated by
  548. * the hardware and we must re-read to get a clean value.
  549. */
  550. limit = 1000;
  551. do {
  552. afsr = schizo_read(afsr_reg);
  553. } while ((afsr & SCHIZO_UEAFSR_ERRPNDG) != 0 && --limit);
  554. /* Clear primary/secondary error status bits. */
  555. error_bits = afsr &
  556. (SCHIZO_CEAFSR_PPIO | SCHIZO_CEAFSR_PDRD | SCHIZO_CEAFSR_PDWR |
  557. SCHIZO_CEAFSR_SPIO | SCHIZO_CEAFSR_SDMA);
  558. if (!error_bits)
  559. return IRQ_NONE;
  560. schizo_write(afsr_reg, error_bits);
  561. /* Log the error. */
  562. printk("PCI%d: Correctable Error, primary error type[%s]\n",
  563. p->index,
  564. (((error_bits & SCHIZO_CEAFSR_PPIO) ?
  565. "PIO" :
  566. ((error_bits & SCHIZO_CEAFSR_PDRD) ?
  567. "DMA Read" :
  568. ((error_bits & SCHIZO_CEAFSR_PDWR) ?
  569. "DMA Write" : "???")))));
  570. /* XXX Use syndrome and afar to print out module string just like
  571. * XXX UDB CE trap handler does... -DaveM
  572. */
  573. printk("PCI%d: bytemask[%04lx] qword_offset[%lx] SAFARI_AID[%02lx]\n",
  574. p->index,
  575. (afsr & SCHIZO_UEAFSR_BMSK) >> 32UL,
  576. (afsr & SCHIZO_UEAFSR_QOFF) >> 30UL,
  577. (afsr & SCHIZO_UEAFSR_AID) >> 24UL);
  578. printk("PCI%d: partial[%d] owned_in[%d] mtag[%lx] mtag_synd[%lx] ecc_sync[%lx]\n",
  579. p->index,
  580. (afsr & SCHIZO_UEAFSR_PARTIAL) ? 1 : 0,
  581. (afsr & SCHIZO_UEAFSR_OWNEDIN) ? 1 : 0,
  582. (afsr & SCHIZO_UEAFSR_MTAG) >> 13UL,
  583. (afsr & SCHIZO_UEAFSR_MTAGSYND) >> 16UL,
  584. (afsr & SCHIZO_UEAFSR_ECCSYND) >> 0UL);
  585. printk("PCI%d: CE AFAR [%016lx]\n", p->index, afar);
  586. printk("PCI%d: CE Secondary errors [", p->index);
  587. reported = 0;
  588. if (afsr & SCHIZO_CEAFSR_SPIO) {
  589. reported++;
  590. printk("(PIO)");
  591. }
  592. if (afsr & SCHIZO_CEAFSR_SDMA) {
  593. reported++;
  594. printk("(DMA)");
  595. }
  596. if (!reported)
  597. printk("(none)");
  598. printk("]\n");
  599. return IRQ_HANDLED;
  600. }
  601. #define SCHIZO_PCI_AFSR 0x2010UL
  602. #define SCHIZO_PCI_AFAR 0x2018UL
  603. #define SCHIZO_PCIAFSR_PMA 0x8000000000000000UL /* Schizo/Tomatillo */
  604. #define SCHIZO_PCIAFSR_PTA 0x4000000000000000UL /* Schizo/Tomatillo */
  605. #define SCHIZO_PCIAFSR_PRTRY 0x2000000000000000UL /* Schizo/Tomatillo */
  606. #define SCHIZO_PCIAFSR_PPERR 0x1000000000000000UL /* Schizo/Tomatillo */
  607. #define SCHIZO_PCIAFSR_PTTO 0x0800000000000000UL /* Schizo/Tomatillo */
  608. #define SCHIZO_PCIAFSR_PUNUS 0x0400000000000000UL /* Schizo */
  609. #define SCHIZO_PCIAFSR_SMA 0x0200000000000000UL /* Schizo/Tomatillo */
  610. #define SCHIZO_PCIAFSR_STA 0x0100000000000000UL /* Schizo/Tomatillo */
  611. #define SCHIZO_PCIAFSR_SRTRY 0x0080000000000000UL /* Schizo/Tomatillo */
  612. #define SCHIZO_PCIAFSR_SPERR 0x0040000000000000UL /* Schizo/Tomatillo */
  613. #define SCHIZO_PCIAFSR_STTO 0x0020000000000000UL /* Schizo/Tomatillo */
  614. #define SCHIZO_PCIAFSR_SUNUS 0x0010000000000000UL /* Schizo */
  615. #define SCHIZO_PCIAFSR_BMSK 0x000003ff00000000UL /* Schizo/Tomatillo */
  616. #define SCHIZO_PCIAFSR_BLK 0x0000000080000000UL /* Schizo/Tomatillo */
  617. #define SCHIZO_PCIAFSR_CFG 0x0000000040000000UL /* Schizo/Tomatillo */
  618. #define SCHIZO_PCIAFSR_MEM 0x0000000020000000UL /* Schizo/Tomatillo */
  619. #define SCHIZO_PCIAFSR_IO 0x0000000010000000UL /* Schizo/Tomatillo */
  620. #define SCHIZO_PCI_CTRL (0x2000UL)
  621. #define SCHIZO_PCICTRL_BUS_UNUS (1UL << 63UL) /* Safari */
  622. #define SCHIZO_PCICTRL_DTO_INT (1UL << 61UL) /* Tomatillo */
  623. #define SCHIZO_PCICTRL_ARB_PRIO (0x1ff << 52UL) /* Tomatillo */
  624. #define SCHIZO_PCICTRL_ESLCK (1UL << 51UL) /* Safari */
  625. #define SCHIZO_PCICTRL_ERRSLOT (7UL << 48UL) /* Safari */
  626. #define SCHIZO_PCICTRL_TTO_ERR (1UL << 38UL) /* Safari/Tomatillo */
  627. #define SCHIZO_PCICTRL_RTRY_ERR (1UL << 37UL) /* Safari/Tomatillo */
  628. #define SCHIZO_PCICTRL_DTO_ERR (1UL << 36UL) /* Safari/Tomatillo */
  629. #define SCHIZO_PCICTRL_SBH_ERR (1UL << 35UL) /* Safari */
  630. #define SCHIZO_PCICTRL_SERR (1UL << 34UL) /* Safari/Tomatillo */
  631. #define SCHIZO_PCICTRL_PCISPD (1UL << 33UL) /* Safari */
  632. #define SCHIZO_PCICTRL_MRM_PREF (1UL << 30UL) /* Tomatillo */
  633. #define SCHIZO_PCICTRL_RDO_PREF (1UL << 29UL) /* Tomatillo */
  634. #define SCHIZO_PCICTRL_RDL_PREF (1UL << 28UL) /* Tomatillo */
  635. #define SCHIZO_PCICTRL_PTO (3UL << 24UL) /* Safari/Tomatillo */
  636. #define SCHIZO_PCICTRL_PTO_SHIFT 24UL
  637. #define SCHIZO_PCICTRL_TRWSW (7UL << 21UL) /* Tomatillo */
  638. #define SCHIZO_PCICTRL_F_TGT_A (1UL << 20UL) /* Tomatillo */
  639. #define SCHIZO_PCICTRL_S_DTO_INT (1UL << 19UL) /* Safari */
  640. #define SCHIZO_PCICTRL_F_TGT_RT (1UL << 19UL) /* Tomatillo */
  641. #define SCHIZO_PCICTRL_SBH_INT (1UL << 18UL) /* Safari */
  642. #define SCHIZO_PCICTRL_T_DTO_INT (1UL << 18UL) /* Tomatillo */
  643. #define SCHIZO_PCICTRL_EEN (1UL << 17UL) /* Safari/Tomatillo */
  644. #define SCHIZO_PCICTRL_PARK (1UL << 16UL) /* Safari/Tomatillo */
  645. #define SCHIZO_PCICTRL_PCIRST (1UL << 8UL) /* Safari */
  646. #define SCHIZO_PCICTRL_ARB_S (0x3fUL << 0UL) /* Safari */
  647. #define SCHIZO_PCICTRL_ARB_T (0xffUL << 0UL) /* Tomatillo */
  648. static irqreturn_t schizo_pcierr_intr_other(struct pci_pbm_info *pbm)
  649. {
  650. unsigned long csr_reg, csr, csr_error_bits;
  651. irqreturn_t ret = IRQ_NONE;
  652. u16 stat;
  653. csr_reg = pbm->pbm_regs + SCHIZO_PCI_CTRL;
  654. csr = schizo_read(csr_reg);
  655. csr_error_bits =
  656. csr & (SCHIZO_PCICTRL_BUS_UNUS |
  657. SCHIZO_PCICTRL_TTO_ERR |
  658. SCHIZO_PCICTRL_RTRY_ERR |
  659. SCHIZO_PCICTRL_DTO_ERR |
  660. SCHIZO_PCICTRL_SBH_ERR |
  661. SCHIZO_PCICTRL_SERR);
  662. if (csr_error_bits) {
  663. /* Clear the errors. */
  664. schizo_write(csr_reg, csr);
  665. /* Log 'em. */
  666. if (csr_error_bits & SCHIZO_PCICTRL_BUS_UNUS)
  667. printk("%s: Bus unusable error asserted.\n",
  668. pbm->name);
  669. if (csr_error_bits & SCHIZO_PCICTRL_TTO_ERR)
  670. printk("%s: PCI TRDY# timeout error asserted.\n",
  671. pbm->name);
  672. if (csr_error_bits & SCHIZO_PCICTRL_RTRY_ERR)
  673. printk("%s: PCI excessive retry error asserted.\n",
  674. pbm->name);
  675. if (csr_error_bits & SCHIZO_PCICTRL_DTO_ERR)
  676. printk("%s: PCI discard timeout error asserted.\n",
  677. pbm->name);
  678. if (csr_error_bits & SCHIZO_PCICTRL_SBH_ERR)
  679. printk("%s: PCI streaming byte hole error asserted.\n",
  680. pbm->name);
  681. if (csr_error_bits & SCHIZO_PCICTRL_SERR)
  682. printk("%s: PCI SERR signal asserted.\n",
  683. pbm->name);
  684. ret = IRQ_HANDLED;
  685. }
  686. pci_read_config_word(pbm->pci_bus->self, PCI_STATUS, &stat);
  687. if (stat & (PCI_STATUS_PARITY |
  688. PCI_STATUS_SIG_TARGET_ABORT |
  689. PCI_STATUS_REC_TARGET_ABORT |
  690. PCI_STATUS_REC_MASTER_ABORT |
  691. PCI_STATUS_SIG_SYSTEM_ERROR)) {
  692. printk("%s: PCI bus error, PCI_STATUS[%04x]\n",
  693. pbm->name, stat);
  694. pci_write_config_word(pbm->pci_bus->self, PCI_STATUS, 0xffff);
  695. ret = IRQ_HANDLED;
  696. }
  697. return ret;
  698. }
  699. static irqreturn_t schizo_pcierr_intr(int irq, void *dev_id)
  700. {
  701. struct pci_pbm_info *pbm = dev_id;
  702. struct pci_controller_info *p = pbm->parent;
  703. unsigned long afsr_reg, afar_reg, base;
  704. unsigned long afsr, afar, error_bits;
  705. int reported;
  706. base = pbm->pbm_regs;
  707. afsr_reg = base + SCHIZO_PCI_AFSR;
  708. afar_reg = base + SCHIZO_PCI_AFAR;
  709. /* Latch error status. */
  710. afar = schizo_read(afar_reg);
  711. afsr = schizo_read(afsr_reg);
  712. /* Clear primary/secondary error status bits. */
  713. error_bits = afsr &
  714. (SCHIZO_PCIAFSR_PMA | SCHIZO_PCIAFSR_PTA |
  715. SCHIZO_PCIAFSR_PRTRY | SCHIZO_PCIAFSR_PPERR |
  716. SCHIZO_PCIAFSR_PTTO | SCHIZO_PCIAFSR_PUNUS |
  717. SCHIZO_PCIAFSR_SMA | SCHIZO_PCIAFSR_STA |
  718. SCHIZO_PCIAFSR_SRTRY | SCHIZO_PCIAFSR_SPERR |
  719. SCHIZO_PCIAFSR_STTO | SCHIZO_PCIAFSR_SUNUS);
  720. if (!error_bits)
  721. return schizo_pcierr_intr_other(pbm);
  722. schizo_write(afsr_reg, error_bits);
  723. /* Log the error. */
  724. printk("%s: PCI Error, primary error type[%s]\n",
  725. pbm->name,
  726. (((error_bits & SCHIZO_PCIAFSR_PMA) ?
  727. "Master Abort" :
  728. ((error_bits & SCHIZO_PCIAFSR_PTA) ?
  729. "Target Abort" :
  730. ((error_bits & SCHIZO_PCIAFSR_PRTRY) ?
  731. "Excessive Retries" :
  732. ((error_bits & SCHIZO_PCIAFSR_PPERR) ?
  733. "Parity Error" :
  734. ((error_bits & SCHIZO_PCIAFSR_PTTO) ?
  735. "Timeout" :
  736. ((error_bits & SCHIZO_PCIAFSR_PUNUS) ?
  737. "Bus Unusable" : "???"))))))));
  738. printk("%s: bytemask[%04lx] was_block(%d) space(%s)\n",
  739. pbm->name,
  740. (afsr & SCHIZO_PCIAFSR_BMSK) >> 32UL,
  741. (afsr & SCHIZO_PCIAFSR_BLK) ? 1 : 0,
  742. ((afsr & SCHIZO_PCIAFSR_CFG) ?
  743. "Config" :
  744. ((afsr & SCHIZO_PCIAFSR_MEM) ?
  745. "Memory" :
  746. ((afsr & SCHIZO_PCIAFSR_IO) ?
  747. "I/O" : "???"))));
  748. printk("%s: PCI AFAR [%016lx]\n",
  749. pbm->name, afar);
  750. printk("%s: PCI Secondary errors [",
  751. pbm->name);
  752. reported = 0;
  753. if (afsr & SCHIZO_PCIAFSR_SMA) {
  754. reported++;
  755. printk("(Master Abort)");
  756. }
  757. if (afsr & SCHIZO_PCIAFSR_STA) {
  758. reported++;
  759. printk("(Target Abort)");
  760. }
  761. if (afsr & SCHIZO_PCIAFSR_SRTRY) {
  762. reported++;
  763. printk("(Excessive Retries)");
  764. }
  765. if (afsr & SCHIZO_PCIAFSR_SPERR) {
  766. reported++;
  767. printk("(Parity Error)");
  768. }
  769. if (afsr & SCHIZO_PCIAFSR_STTO) {
  770. reported++;
  771. printk("(Timeout)");
  772. }
  773. if (afsr & SCHIZO_PCIAFSR_SUNUS) {
  774. reported++;
  775. printk("(Bus Unusable)");
  776. }
  777. if (!reported)
  778. printk("(none)");
  779. printk("]\n");
  780. /* For the error types shown, scan PBM's PCI bus for devices
  781. * which have logged that error type.
  782. */
  783. /* If we see a Target Abort, this could be the result of an
  784. * IOMMU translation error of some sort. It is extremely
  785. * useful to log this information as usually it indicates
  786. * a bug in the IOMMU support code or a PCI device driver.
  787. */
  788. if (error_bits & (SCHIZO_PCIAFSR_PTA | SCHIZO_PCIAFSR_STA)) {
  789. schizo_check_iommu_error(p, PCI_ERR);
  790. pci_scan_for_target_abort(p, pbm, pbm->pci_bus);
  791. }
  792. if (error_bits & (SCHIZO_PCIAFSR_PMA | SCHIZO_PCIAFSR_SMA))
  793. pci_scan_for_master_abort(p, pbm, pbm->pci_bus);
  794. /* For excessive retries, PSYCHO/PBM will abort the device
  795. * and there is no way to specifically check for excessive
  796. * retries in the config space status registers. So what
  797. * we hope is that we'll catch it via the master/target
  798. * abort events.
  799. */
  800. if (error_bits & (SCHIZO_PCIAFSR_PPERR | SCHIZO_PCIAFSR_SPERR))
  801. pci_scan_for_parity_error(p, pbm, pbm->pci_bus);
  802. return IRQ_HANDLED;
  803. }
  804. #define SCHIZO_SAFARI_ERRLOG 0x10018UL
  805. #define SAFARI_ERRLOG_ERROUT 0x8000000000000000UL
  806. #define BUS_ERROR_BADCMD 0x4000000000000000UL /* Schizo/Tomatillo */
  807. #define BUS_ERROR_SSMDIS 0x2000000000000000UL /* Safari */
  808. #define BUS_ERROR_BADMA 0x1000000000000000UL /* Safari */
  809. #define BUS_ERROR_BADMB 0x0800000000000000UL /* Safari */
  810. #define BUS_ERROR_BADMC 0x0400000000000000UL /* Safari */
  811. #define BUS_ERROR_SNOOP_GR 0x0000000000200000UL /* Tomatillo */
  812. #define BUS_ERROR_SNOOP_PCI 0x0000000000100000UL /* Tomatillo */
  813. #define BUS_ERROR_SNOOP_RD 0x0000000000080000UL /* Tomatillo */
  814. #define BUS_ERROR_SNOOP_RDS 0x0000000000020000UL /* Tomatillo */
  815. #define BUS_ERROR_SNOOP_RDSA 0x0000000000010000UL /* Tomatillo */
  816. #define BUS_ERROR_SNOOP_OWN 0x0000000000008000UL /* Tomatillo */
  817. #define BUS_ERROR_SNOOP_RDO 0x0000000000004000UL /* Tomatillo */
  818. #define BUS_ERROR_CPU1PS 0x0000000000002000UL /* Safari */
  819. #define BUS_ERROR_WDATA_PERR 0x0000000000002000UL /* Tomatillo */
  820. #define BUS_ERROR_CPU1PB 0x0000000000001000UL /* Safari */
  821. #define BUS_ERROR_CTRL_PERR 0x0000000000001000UL /* Tomatillo */
  822. #define BUS_ERROR_CPU0PS 0x0000000000000800UL /* Safari */
  823. #define BUS_ERROR_SNOOP_ERR 0x0000000000000800UL /* Tomatillo */
  824. #define BUS_ERROR_CPU0PB 0x0000000000000400UL /* Safari */
  825. #define BUS_ERROR_JBUS_ILL_B 0x0000000000000400UL /* Tomatillo */
  826. #define BUS_ERROR_CIQTO 0x0000000000000200UL /* Safari */
  827. #define BUS_ERROR_LPQTO 0x0000000000000100UL /* Safari */
  828. #define BUS_ERROR_JBUS_ILL_C 0x0000000000000100UL /* Tomatillo */
  829. #define BUS_ERROR_SFPQTO 0x0000000000000080UL /* Safari */
  830. #define BUS_ERROR_UFPQTO 0x0000000000000040UL /* Safari */
  831. #define BUS_ERROR_RD_PERR 0x0000000000000040UL /* Tomatillo */
  832. #define BUS_ERROR_APERR 0x0000000000000020UL /* Safari/Tomatillo */
  833. #define BUS_ERROR_UNMAP 0x0000000000000010UL /* Safari/Tomatillo */
  834. #define BUS_ERROR_BUSERR 0x0000000000000004UL /* Safari/Tomatillo */
  835. #define BUS_ERROR_TIMEOUT 0x0000000000000002UL /* Safari/Tomatillo */
  836. #define BUS_ERROR_ILL 0x0000000000000001UL /* Safari */
  837. /* We only expect UNMAP errors here. The rest of the Safari errors
  838. * are marked fatal and thus cause a system reset.
  839. */
  840. static irqreturn_t schizo_safarierr_intr(int irq, void *dev_id)
  841. {
  842. struct pci_controller_info *p = dev_id;
  843. u64 errlog;
  844. errlog = schizo_read(p->pbm_B.controller_regs + SCHIZO_SAFARI_ERRLOG);
  845. schizo_write(p->pbm_B.controller_regs + SCHIZO_SAFARI_ERRLOG,
  846. errlog & ~(SAFARI_ERRLOG_ERROUT));
  847. if (!(errlog & BUS_ERROR_UNMAP)) {
  848. printk("PCI%d: Unexpected Safari/JBUS error interrupt, errlog[%016lx]\n",
  849. p->index, errlog);
  850. return IRQ_HANDLED;
  851. }
  852. printk("PCI%d: Safari/JBUS interrupt, UNMAPPED error, interrogating IOMMUs.\n",
  853. p->index);
  854. schizo_check_iommu_error(p, SAFARI_ERR);
  855. return IRQ_HANDLED;
  856. }
  857. /* Nearly identical to PSYCHO equivalents... */
  858. #define SCHIZO_ECC_CTRL 0x10020UL
  859. #define SCHIZO_ECCCTRL_EE 0x8000000000000000UL /* Enable ECC Checking */
  860. #define SCHIZO_ECCCTRL_UE 0x4000000000000000UL /* Enable UE Interrupts */
  861. #define SCHIZO_ECCCTRL_CE 0x2000000000000000UL /* Enable CE INterrupts */
  862. #define SCHIZO_SAFARI_ERRCTRL 0x10008UL
  863. #define SCHIZO_SAFERRCTRL_EN 0x8000000000000000UL
  864. #define SCHIZO_SAFARI_IRQCTRL 0x10010UL
  865. #define SCHIZO_SAFIRQCTRL_EN 0x8000000000000000UL
  866. /* How the Tomatillo IRQs are routed around is pure guesswork here.
  867. *
  868. * All the Tomatillo devices I see in prtconf dumps seem to have only
  869. * a single PCI bus unit attached to it. It would seem they are seperate
  870. * devices because their PortID (ie. JBUS ID) values are all different
  871. * and thus the registers are mapped to totally different locations.
  872. *
  873. * However, two Tomatillo's look "similar" in that the only difference
  874. * in their PortID is the lowest bit.
  875. *
  876. * So if we were to ignore this lower bit, it certainly looks like two
  877. * PCI bus units of the same Tomatillo. I still have not really
  878. * figured this out...
  879. */
  880. static void tomatillo_register_error_handlers(struct pci_controller_info *p)
  881. {
  882. struct pci_pbm_info *pbm;
  883. struct of_device *op;
  884. u64 tmp, err_mask, err_no_mask;
  885. /* Tomatillo IRQ property layout is:
  886. * 0: PCIERR
  887. * 1: UE ERR
  888. * 2: CE ERR
  889. * 3: SERR
  890. * 4: POWER FAIL?
  891. */
  892. pbm = pbm_for_ino(p, SCHIZO_UE_INO);
  893. op = of_find_device_by_node(pbm->prom_node);
  894. if (op)
  895. request_irq(op->irqs[1], schizo_ue_intr, IRQF_SHARED,
  896. "TOMATILLO_UE", p);
  897. pbm = pbm_for_ino(p, SCHIZO_CE_INO);
  898. op = of_find_device_by_node(pbm->prom_node);
  899. if (op)
  900. request_irq(op->irqs[2], schizo_ce_intr, IRQF_SHARED,
  901. "TOMATILLO CE", p);
  902. pbm = pbm_for_ino(p, SCHIZO_PCIERR_A_INO);
  903. op = of_find_device_by_node(pbm->prom_node);
  904. if (op)
  905. request_irq(op->irqs[0], schizo_pcierr_intr, IRQF_SHARED,
  906. "TOMATILLO PCIERR-A", pbm);
  907. pbm = pbm_for_ino(p, SCHIZO_PCIERR_B_INO);
  908. op = of_find_device_by_node(pbm->prom_node);
  909. if (op)
  910. request_irq(op->irqs[0], schizo_pcierr_intr, IRQF_SHARED,
  911. "TOMATILLO PCIERR-B", pbm);
  912. pbm = pbm_for_ino(p, SCHIZO_SERR_INO);
  913. op = of_find_device_by_node(pbm->prom_node);
  914. if (op)
  915. request_irq(op->irqs[3], schizo_safarierr_intr, IRQF_SHARED,
  916. "TOMATILLO SERR", p);
  917. /* Enable UE and CE interrupts for controller. */
  918. schizo_write(p->pbm_A.controller_regs + SCHIZO_ECC_CTRL,
  919. (SCHIZO_ECCCTRL_EE |
  920. SCHIZO_ECCCTRL_UE |
  921. SCHIZO_ECCCTRL_CE));
  922. schizo_write(p->pbm_B.controller_regs + SCHIZO_ECC_CTRL,
  923. (SCHIZO_ECCCTRL_EE |
  924. SCHIZO_ECCCTRL_UE |
  925. SCHIZO_ECCCTRL_CE));
  926. /* Enable PCI Error interrupts and clear error
  927. * bits.
  928. */
  929. err_mask = (SCHIZO_PCICTRL_BUS_UNUS |
  930. SCHIZO_PCICTRL_TTO_ERR |
  931. SCHIZO_PCICTRL_RTRY_ERR |
  932. SCHIZO_PCICTRL_SERR |
  933. SCHIZO_PCICTRL_EEN);
  934. err_no_mask = SCHIZO_PCICTRL_DTO_ERR;
  935. tmp = schizo_read(p->pbm_A.pbm_regs + SCHIZO_PCI_CTRL);
  936. tmp |= err_mask;
  937. tmp &= ~err_no_mask;
  938. schizo_write(p->pbm_A.pbm_regs + SCHIZO_PCI_CTRL, tmp);
  939. tmp = schizo_read(p->pbm_B.pbm_regs + SCHIZO_PCI_CTRL);
  940. tmp |= err_mask;
  941. tmp &= ~err_no_mask;
  942. schizo_write(p->pbm_B.pbm_regs + SCHIZO_PCI_CTRL, tmp);
  943. err_mask = (SCHIZO_PCIAFSR_PMA | SCHIZO_PCIAFSR_PTA |
  944. SCHIZO_PCIAFSR_PRTRY | SCHIZO_PCIAFSR_PPERR |
  945. SCHIZO_PCIAFSR_PTTO |
  946. SCHIZO_PCIAFSR_SMA | SCHIZO_PCIAFSR_STA |
  947. SCHIZO_PCIAFSR_SRTRY | SCHIZO_PCIAFSR_SPERR |
  948. SCHIZO_PCIAFSR_STTO);
  949. schizo_write(p->pbm_A.pbm_regs + SCHIZO_PCI_AFSR, err_mask);
  950. schizo_write(p->pbm_B.pbm_regs + SCHIZO_PCI_AFSR, err_mask);
  951. err_mask = (BUS_ERROR_BADCMD | BUS_ERROR_SNOOP_GR |
  952. BUS_ERROR_SNOOP_PCI | BUS_ERROR_SNOOP_RD |
  953. BUS_ERROR_SNOOP_RDS | BUS_ERROR_SNOOP_RDSA |
  954. BUS_ERROR_SNOOP_OWN | BUS_ERROR_SNOOP_RDO |
  955. BUS_ERROR_WDATA_PERR | BUS_ERROR_CTRL_PERR |
  956. BUS_ERROR_SNOOP_ERR | BUS_ERROR_JBUS_ILL_B |
  957. BUS_ERROR_JBUS_ILL_C | BUS_ERROR_RD_PERR |
  958. BUS_ERROR_APERR | BUS_ERROR_UNMAP |
  959. BUS_ERROR_BUSERR | BUS_ERROR_TIMEOUT);
  960. schizo_write(p->pbm_A.controller_regs + SCHIZO_SAFARI_ERRCTRL,
  961. (SCHIZO_SAFERRCTRL_EN | err_mask));
  962. schizo_write(p->pbm_B.controller_regs + SCHIZO_SAFARI_ERRCTRL,
  963. (SCHIZO_SAFERRCTRL_EN | err_mask));
  964. schizo_write(p->pbm_A.controller_regs + SCHIZO_SAFARI_IRQCTRL,
  965. (SCHIZO_SAFIRQCTRL_EN | (BUS_ERROR_UNMAP)));
  966. schizo_write(p->pbm_B.controller_regs + SCHIZO_SAFARI_IRQCTRL,
  967. (SCHIZO_SAFIRQCTRL_EN | (BUS_ERROR_UNMAP)));
  968. }
  969. static void schizo_register_error_handlers(struct pci_controller_info *p)
  970. {
  971. struct pci_pbm_info *pbm;
  972. struct of_device *op;
  973. u64 tmp, err_mask, err_no_mask;
  974. /* Schizo IRQ property layout is:
  975. * 0: PCIERR
  976. * 1: UE ERR
  977. * 2: CE ERR
  978. * 3: SERR
  979. * 4: POWER FAIL?
  980. */
  981. pbm = pbm_for_ino(p, SCHIZO_UE_INO);
  982. op = of_find_device_by_node(pbm->prom_node);
  983. if (op)
  984. request_irq(op->irqs[1], schizo_ue_intr, IRQF_SHARED,
  985. "SCHIZO_UE", p);
  986. pbm = pbm_for_ino(p, SCHIZO_CE_INO);
  987. op = of_find_device_by_node(pbm->prom_node);
  988. if (op)
  989. request_irq(op->irqs[2], schizo_ce_intr, IRQF_SHARED,
  990. "SCHIZO CE", p);
  991. pbm = pbm_for_ino(p, SCHIZO_PCIERR_A_INO);
  992. op = of_find_device_by_node(pbm->prom_node);
  993. if (op)
  994. request_irq(op->irqs[0], schizo_pcierr_intr, IRQF_SHARED,
  995. "SCHIZO PCIERR-A", pbm);
  996. pbm = pbm_for_ino(p, SCHIZO_PCIERR_B_INO);
  997. op = of_find_device_by_node(pbm->prom_node);
  998. if (op)
  999. request_irq(op->irqs[0], schizo_pcierr_intr, IRQF_SHARED,
  1000. "SCHIZO PCIERR-B", pbm);
  1001. pbm = pbm_for_ino(p, SCHIZO_SERR_INO);
  1002. op = of_find_device_by_node(pbm->prom_node);
  1003. if (op)
  1004. request_irq(op->irqs[3], schizo_safarierr_intr, IRQF_SHARED,
  1005. "SCHIZO SERR", p);
  1006. /* Enable UE and CE interrupts for controller. */
  1007. schizo_write(p->pbm_A.controller_regs + SCHIZO_ECC_CTRL,
  1008. (SCHIZO_ECCCTRL_EE |
  1009. SCHIZO_ECCCTRL_UE |
  1010. SCHIZO_ECCCTRL_CE));
  1011. err_mask = (SCHIZO_PCICTRL_BUS_UNUS |
  1012. SCHIZO_PCICTRL_ESLCK |
  1013. SCHIZO_PCICTRL_TTO_ERR |
  1014. SCHIZO_PCICTRL_RTRY_ERR |
  1015. SCHIZO_PCICTRL_SBH_ERR |
  1016. SCHIZO_PCICTRL_SERR |
  1017. SCHIZO_PCICTRL_EEN);
  1018. err_no_mask = (SCHIZO_PCICTRL_DTO_ERR |
  1019. SCHIZO_PCICTRL_SBH_INT);
  1020. /* Enable PCI Error interrupts and clear error
  1021. * bits for each PBM.
  1022. */
  1023. tmp = schizo_read(p->pbm_A.pbm_regs + SCHIZO_PCI_CTRL);
  1024. tmp |= err_mask;
  1025. tmp &= ~err_no_mask;
  1026. schizo_write(p->pbm_A.pbm_regs + SCHIZO_PCI_CTRL, tmp);
  1027. schizo_write(p->pbm_A.pbm_regs + SCHIZO_PCI_AFSR,
  1028. (SCHIZO_PCIAFSR_PMA | SCHIZO_PCIAFSR_PTA |
  1029. SCHIZO_PCIAFSR_PRTRY | SCHIZO_PCIAFSR_PPERR |
  1030. SCHIZO_PCIAFSR_PTTO | SCHIZO_PCIAFSR_PUNUS |
  1031. SCHIZO_PCIAFSR_SMA | SCHIZO_PCIAFSR_STA |
  1032. SCHIZO_PCIAFSR_SRTRY | SCHIZO_PCIAFSR_SPERR |
  1033. SCHIZO_PCIAFSR_STTO | SCHIZO_PCIAFSR_SUNUS));
  1034. tmp = schizo_read(p->pbm_B.pbm_regs + SCHIZO_PCI_CTRL);
  1035. tmp |= err_mask;
  1036. tmp &= ~err_no_mask;
  1037. schizo_write(p->pbm_B.pbm_regs + SCHIZO_PCI_CTRL, tmp);
  1038. schizo_write(p->pbm_B.pbm_regs + SCHIZO_PCI_AFSR,
  1039. (SCHIZO_PCIAFSR_PMA | SCHIZO_PCIAFSR_PTA |
  1040. SCHIZO_PCIAFSR_PRTRY | SCHIZO_PCIAFSR_PPERR |
  1041. SCHIZO_PCIAFSR_PTTO | SCHIZO_PCIAFSR_PUNUS |
  1042. SCHIZO_PCIAFSR_SMA | SCHIZO_PCIAFSR_STA |
  1043. SCHIZO_PCIAFSR_SRTRY | SCHIZO_PCIAFSR_SPERR |
  1044. SCHIZO_PCIAFSR_STTO | SCHIZO_PCIAFSR_SUNUS));
  1045. /* Make all Safari error conditions fatal except unmapped
  1046. * errors which we make generate interrupts.
  1047. */
  1048. err_mask = (BUS_ERROR_BADCMD | BUS_ERROR_SSMDIS |
  1049. BUS_ERROR_BADMA | BUS_ERROR_BADMB |
  1050. BUS_ERROR_BADMC |
  1051. BUS_ERROR_CPU1PS | BUS_ERROR_CPU1PB |
  1052. BUS_ERROR_CPU0PS | BUS_ERROR_CPU0PB |
  1053. BUS_ERROR_CIQTO |
  1054. BUS_ERROR_LPQTO | BUS_ERROR_SFPQTO |
  1055. BUS_ERROR_UFPQTO | BUS_ERROR_APERR |
  1056. BUS_ERROR_BUSERR | BUS_ERROR_TIMEOUT |
  1057. BUS_ERROR_ILL);
  1058. #if 1
  1059. /* XXX Something wrong with some Excalibur systems
  1060. * XXX Sun is shipping. The behavior on a 2-cpu
  1061. * XXX machine is that both CPU1 parity error bits
  1062. * XXX are set and are immediately set again when
  1063. * XXX their error status bits are cleared. Just
  1064. * XXX ignore them for now. -DaveM
  1065. */
  1066. err_mask &= ~(BUS_ERROR_CPU1PS | BUS_ERROR_CPU1PB |
  1067. BUS_ERROR_CPU0PS | BUS_ERROR_CPU0PB);
  1068. #endif
  1069. schizo_write(p->pbm_A.controller_regs + SCHIZO_SAFARI_ERRCTRL,
  1070. (SCHIZO_SAFERRCTRL_EN | err_mask));
  1071. schizo_write(p->pbm_A.controller_regs + SCHIZO_SAFARI_IRQCTRL,
  1072. (SCHIZO_SAFIRQCTRL_EN | (BUS_ERROR_UNMAP)));
  1073. }
  1074. static void pbm_config_busmastering(struct pci_pbm_info *pbm)
  1075. {
  1076. u8 *addr;
  1077. /* Set cache-line size to 64 bytes, this is actually
  1078. * a nop but I do it for completeness.
  1079. */
  1080. addr = schizo_pci_config_mkaddr(pbm, pbm->pci_first_busno,
  1081. 0, PCI_CACHE_LINE_SIZE);
  1082. pci_config_write8(addr, 64 / sizeof(u32));
  1083. /* Set PBM latency timer to 64 PCI clocks. */
  1084. addr = schizo_pci_config_mkaddr(pbm, pbm->pci_first_busno,
  1085. 0, PCI_LATENCY_TIMER);
  1086. pci_config_write8(addr, 64);
  1087. }
  1088. static void schizo_scan_bus(struct pci_controller_info *p)
  1089. {
  1090. pbm_config_busmastering(&p->pbm_B);
  1091. p->pbm_B.is_66mhz_capable =
  1092. (of_find_property(p->pbm_B.prom_node, "66mhz-capable", NULL)
  1093. != NULL);
  1094. pbm_config_busmastering(&p->pbm_A);
  1095. p->pbm_A.is_66mhz_capable =
  1096. (of_find_property(p->pbm_A.prom_node, "66mhz-capable", NULL)
  1097. != NULL);
  1098. p->pbm_B.pci_bus = pci_scan_one_pbm(&p->pbm_B);
  1099. p->pbm_A.pci_bus = pci_scan_one_pbm(&p->pbm_A);
  1100. /* After the PCI bus scan is complete, we can register
  1101. * the error interrupt handlers.
  1102. */
  1103. if (p->pbm_B.chip_type == PBM_CHIP_TYPE_TOMATILLO)
  1104. tomatillo_register_error_handlers(p);
  1105. else
  1106. schizo_register_error_handlers(p);
  1107. }
  1108. #define SCHIZO_STRBUF_CONTROL (0x02800UL)
  1109. #define SCHIZO_STRBUF_FLUSH (0x02808UL)
  1110. #define SCHIZO_STRBUF_FSYNC (0x02810UL)
  1111. #define SCHIZO_STRBUF_CTXFLUSH (0x02818UL)
  1112. #define SCHIZO_STRBUF_CTXMATCH (0x10000UL)
  1113. static void schizo_pbm_strbuf_init(struct pci_pbm_info *pbm)
  1114. {
  1115. unsigned long base = pbm->pbm_regs;
  1116. u64 control;
  1117. if (pbm->chip_type == PBM_CHIP_TYPE_TOMATILLO) {
  1118. /* TOMATILLO lacks streaming cache. */
  1119. return;
  1120. }
  1121. /* SCHIZO has context flushing. */
  1122. pbm->stc.strbuf_control = base + SCHIZO_STRBUF_CONTROL;
  1123. pbm->stc.strbuf_pflush = base + SCHIZO_STRBUF_FLUSH;
  1124. pbm->stc.strbuf_fsync = base + SCHIZO_STRBUF_FSYNC;
  1125. pbm->stc.strbuf_ctxflush = base + SCHIZO_STRBUF_CTXFLUSH;
  1126. pbm->stc.strbuf_ctxmatch_base = base + SCHIZO_STRBUF_CTXMATCH;
  1127. pbm->stc.strbuf_flushflag = (volatile unsigned long *)
  1128. ((((unsigned long)&pbm->stc.__flushflag_buf[0])
  1129. + 63UL)
  1130. & ~63UL);
  1131. pbm->stc.strbuf_flushflag_pa = (unsigned long)
  1132. __pa(pbm->stc.strbuf_flushflag);
  1133. /* Turn off LRU locking and diag mode, enable the
  1134. * streaming buffer and leave the rerun-disable
  1135. * setting however OBP set it.
  1136. */
  1137. control = schizo_read(pbm->stc.strbuf_control);
  1138. control &= ~(SCHIZO_STRBUF_CTRL_LPTR |
  1139. SCHIZO_STRBUF_CTRL_LENAB |
  1140. SCHIZO_STRBUF_CTRL_DENAB);
  1141. control |= SCHIZO_STRBUF_CTRL_ENAB;
  1142. schizo_write(pbm->stc.strbuf_control, control);
  1143. pbm->stc.strbuf_enabled = 1;
  1144. }
  1145. #define SCHIZO_IOMMU_CONTROL (0x00200UL)
  1146. #define SCHIZO_IOMMU_TSBBASE (0x00208UL)
  1147. #define SCHIZO_IOMMU_FLUSH (0x00210UL)
  1148. #define SCHIZO_IOMMU_CTXFLUSH (0x00218UL)
  1149. static void schizo_pbm_iommu_init(struct pci_pbm_info *pbm)
  1150. {
  1151. struct iommu *iommu = pbm->iommu;
  1152. unsigned long i, tagbase, database;
  1153. struct property *prop;
  1154. u32 vdma[2], dma_mask;
  1155. u64 control;
  1156. int tsbsize;
  1157. prop = of_find_property(pbm->prom_node, "virtual-dma", NULL);
  1158. if (prop) {
  1159. u32 *val = prop->value;
  1160. vdma[0] = val[0];
  1161. vdma[1] = val[1];
  1162. } else {
  1163. /* No property, use default values. */
  1164. vdma[0] = 0xc0000000;
  1165. vdma[1] = 0x40000000;
  1166. }
  1167. dma_mask = vdma[0];
  1168. switch (vdma[1]) {
  1169. case 0x20000000:
  1170. dma_mask |= 0x1fffffff;
  1171. tsbsize = 64;
  1172. break;
  1173. case 0x40000000:
  1174. dma_mask |= 0x3fffffff;
  1175. tsbsize = 128;
  1176. break;
  1177. case 0x80000000:
  1178. dma_mask |= 0x7fffffff;
  1179. tsbsize = 128;
  1180. break;
  1181. default:
  1182. prom_printf("SCHIZO: strange virtual-dma size.\n");
  1183. prom_halt();
  1184. };
  1185. /* Register addresses, SCHIZO has iommu ctx flushing. */
  1186. iommu->iommu_control = pbm->pbm_regs + SCHIZO_IOMMU_CONTROL;
  1187. iommu->iommu_tsbbase = pbm->pbm_regs + SCHIZO_IOMMU_TSBBASE;
  1188. iommu->iommu_flush = pbm->pbm_regs + SCHIZO_IOMMU_FLUSH;
  1189. iommu->iommu_ctxflush = pbm->pbm_regs + SCHIZO_IOMMU_CTXFLUSH;
  1190. /* We use the main control/status register of SCHIZO as the write
  1191. * completion register.
  1192. */
  1193. iommu->write_complete_reg = pbm->controller_regs + 0x10000UL;
  1194. /*
  1195. * Invalidate TLB Entries.
  1196. */
  1197. control = schizo_read(iommu->iommu_control);
  1198. control |= SCHIZO_IOMMU_CTRL_DENAB;
  1199. schizo_write(iommu->iommu_control, control);
  1200. tagbase = SCHIZO_IOMMU_TAG, database = SCHIZO_IOMMU_DATA;
  1201. for(i = 0; i < 16; i++) {
  1202. schizo_write(pbm->pbm_regs + tagbase + (i * 8UL), 0);
  1203. schizo_write(pbm->pbm_regs + database + (i * 8UL), 0);
  1204. }
  1205. /* Leave diag mode enabled for full-flushing done
  1206. * in pci_iommu.c
  1207. */
  1208. pci_iommu_table_init(iommu, tsbsize * 8 * 1024, vdma[0], dma_mask);
  1209. schizo_write(iommu->iommu_tsbbase, __pa(iommu->page_table));
  1210. control = schizo_read(iommu->iommu_control);
  1211. control &= ~(SCHIZO_IOMMU_CTRL_TSBSZ | SCHIZO_IOMMU_CTRL_TBWSZ);
  1212. switch (tsbsize) {
  1213. case 64:
  1214. control |= SCHIZO_IOMMU_TSBSZ_64K;
  1215. break;
  1216. case 128:
  1217. control |= SCHIZO_IOMMU_TSBSZ_128K;
  1218. break;
  1219. };
  1220. control |= SCHIZO_IOMMU_CTRL_ENAB;
  1221. schizo_write(iommu->iommu_control, control);
  1222. }
  1223. #define SCHIZO_PCI_IRQ_RETRY (0x1a00UL)
  1224. #define SCHIZO_IRQ_RETRY_INF 0xffUL
  1225. #define SCHIZO_PCI_DIAG (0x2020UL)
  1226. #define SCHIZO_PCIDIAG_D_BADECC (1UL << 10UL) /* Disable BAD ECC errors (Schizo) */
  1227. #define SCHIZO_PCIDIAG_D_BYPASS (1UL << 9UL) /* Disable MMU bypass mode (Schizo/Tomatillo) */
  1228. #define SCHIZO_PCIDIAG_D_TTO (1UL << 8UL) /* Disable TTO errors (Schizo/Tomatillo) */
  1229. #define SCHIZO_PCIDIAG_D_RTRYARB (1UL << 7UL) /* Disable retry arbitration (Schizo) */
  1230. #define SCHIZO_PCIDIAG_D_RETRY (1UL << 6UL) /* Disable retry limit (Schizo/Tomatillo) */
  1231. #define SCHIZO_PCIDIAG_D_INTSYNC (1UL << 5UL) /* Disable interrupt/DMA synch (Schizo/Tomatillo) */
  1232. #define SCHIZO_PCIDIAG_I_DMA_PARITY (1UL << 3UL) /* Invert DMA parity (Schizo/Tomatillo) */
  1233. #define SCHIZO_PCIDIAG_I_PIOD_PARITY (1UL << 2UL) /* Invert PIO data parity (Schizo/Tomatillo) */
  1234. #define SCHIZO_PCIDIAG_I_PIOA_PARITY (1UL << 1UL) /* Invert PIO address parity (Schizo/Tomatillo) */
  1235. #define TOMATILLO_PCI_IOC_CSR (0x2248UL)
  1236. #define TOMATILLO_IOC_PART_WPENAB 0x0000000000080000UL
  1237. #define TOMATILLO_IOC_RDMULT_PENAB 0x0000000000040000UL
  1238. #define TOMATILLO_IOC_RDONE_PENAB 0x0000000000020000UL
  1239. #define TOMATILLO_IOC_RDLINE_PENAB 0x0000000000010000UL
  1240. #define TOMATILLO_IOC_RDMULT_PLEN 0x000000000000c000UL
  1241. #define TOMATILLO_IOC_RDMULT_PLEN_SHIFT 14UL
  1242. #define TOMATILLO_IOC_RDONE_PLEN 0x0000000000003000UL
  1243. #define TOMATILLO_IOC_RDONE_PLEN_SHIFT 12UL
  1244. #define TOMATILLO_IOC_RDLINE_PLEN 0x0000000000000c00UL
  1245. #define TOMATILLO_IOC_RDLINE_PLEN_SHIFT 10UL
  1246. #define TOMATILLO_IOC_PREF_OFF 0x00000000000003f8UL
  1247. #define TOMATILLO_IOC_PREF_OFF_SHIFT 3UL
  1248. #define TOMATILLO_IOC_RDMULT_CPENAB 0x0000000000000004UL
  1249. #define TOMATILLO_IOC_RDONE_CPENAB 0x0000000000000002UL
  1250. #define TOMATILLO_IOC_RDLINE_CPENAB 0x0000000000000001UL
  1251. #define TOMATILLO_PCI_IOC_TDIAG (0x2250UL)
  1252. #define TOMATILLO_PCI_IOC_DDIAG (0x2290UL)
  1253. static void schizo_pbm_hw_init(struct pci_pbm_info *pbm)
  1254. {
  1255. struct property *prop;
  1256. u64 tmp;
  1257. schizo_write(pbm->pbm_regs + SCHIZO_PCI_IRQ_RETRY, 5);
  1258. tmp = schizo_read(pbm->pbm_regs + SCHIZO_PCI_CTRL);
  1259. /* Enable arbiter for all PCI slots. */
  1260. tmp |= 0xff;
  1261. if (pbm->chip_type == PBM_CHIP_TYPE_TOMATILLO &&
  1262. pbm->chip_version >= 0x2)
  1263. tmp |= 0x3UL << SCHIZO_PCICTRL_PTO_SHIFT;
  1264. prop = of_find_property(pbm->prom_node, "no-bus-parking", NULL);
  1265. if (!prop)
  1266. tmp |= SCHIZO_PCICTRL_PARK;
  1267. else
  1268. tmp &= ~SCHIZO_PCICTRL_PARK;
  1269. if (pbm->chip_type == PBM_CHIP_TYPE_TOMATILLO &&
  1270. pbm->chip_version <= 0x1)
  1271. tmp |= SCHIZO_PCICTRL_DTO_INT;
  1272. else
  1273. tmp &= ~SCHIZO_PCICTRL_DTO_INT;
  1274. if (pbm->chip_type == PBM_CHIP_TYPE_TOMATILLO)
  1275. tmp |= (SCHIZO_PCICTRL_MRM_PREF |
  1276. SCHIZO_PCICTRL_RDO_PREF |
  1277. SCHIZO_PCICTRL_RDL_PREF);
  1278. schizo_write(pbm->pbm_regs + SCHIZO_PCI_CTRL, tmp);
  1279. tmp = schizo_read(pbm->pbm_regs + SCHIZO_PCI_DIAG);
  1280. tmp &= ~(SCHIZO_PCIDIAG_D_RTRYARB |
  1281. SCHIZO_PCIDIAG_D_RETRY |
  1282. SCHIZO_PCIDIAG_D_INTSYNC);
  1283. schizo_write(pbm->pbm_regs + SCHIZO_PCI_DIAG, tmp);
  1284. if (pbm->chip_type == PBM_CHIP_TYPE_TOMATILLO) {
  1285. /* Clear prefetch lengths to workaround a bug in
  1286. * Jalapeno...
  1287. */
  1288. tmp = (TOMATILLO_IOC_PART_WPENAB |
  1289. (1 << TOMATILLO_IOC_PREF_OFF_SHIFT) |
  1290. TOMATILLO_IOC_RDMULT_CPENAB |
  1291. TOMATILLO_IOC_RDONE_CPENAB |
  1292. TOMATILLO_IOC_RDLINE_CPENAB);
  1293. schizo_write(pbm->pbm_regs + TOMATILLO_PCI_IOC_CSR,
  1294. tmp);
  1295. }
  1296. }
  1297. static void schizo_pbm_init(struct pci_controller_info *p,
  1298. struct device_node *dp, u32 portid,
  1299. int chip_type)
  1300. {
  1301. const struct linux_prom64_registers *regs;
  1302. const unsigned int *busrange;
  1303. struct pci_pbm_info *pbm;
  1304. const char *chipset_name;
  1305. const u32 *ino_bitmap;
  1306. int is_pbm_a;
  1307. switch (chip_type) {
  1308. case PBM_CHIP_TYPE_TOMATILLO:
  1309. chipset_name = "TOMATILLO";
  1310. break;
  1311. case PBM_CHIP_TYPE_SCHIZO_PLUS:
  1312. chipset_name = "SCHIZO+";
  1313. break;
  1314. case PBM_CHIP_TYPE_SCHIZO:
  1315. default:
  1316. chipset_name = "SCHIZO";
  1317. break;
  1318. };
  1319. /* For SCHIZO, three OBP regs:
  1320. * 1) PBM controller regs
  1321. * 2) Schizo front-end controller regs (same for both PBMs)
  1322. * 3) PBM PCI config space
  1323. *
  1324. * For TOMATILLO, four OBP regs:
  1325. * 1) PBM controller regs
  1326. * 2) Tomatillo front-end controller regs
  1327. * 3) PBM PCI config space
  1328. * 4) Ichip regs
  1329. */
  1330. regs = of_get_property(dp, "reg", NULL);
  1331. is_pbm_a = ((regs[0].phys_addr & 0x00700000) == 0x00600000);
  1332. if (is_pbm_a)
  1333. pbm = &p->pbm_A;
  1334. else
  1335. pbm = &p->pbm_B;
  1336. pbm->portid = portid;
  1337. pbm->parent = p;
  1338. pbm->prom_node = dp;
  1339. pbm->chip_type = chip_type;
  1340. pbm->chip_version = of_getintprop_default(dp, "version#", 0);
  1341. pbm->chip_revision = of_getintprop_default(dp, "module-version#", 0);
  1342. pbm->pbm_regs = regs[0].phys_addr;
  1343. pbm->controller_regs = regs[1].phys_addr - 0x10000UL;
  1344. if (chip_type == PBM_CHIP_TYPE_TOMATILLO)
  1345. pbm->sync_reg = regs[3].phys_addr + 0x1a18UL;
  1346. pbm->name = dp->full_name;
  1347. printk("%s: %s PCI Bus Module ver[%x:%x]\n",
  1348. pbm->name, chipset_name,
  1349. pbm->chip_version, pbm->chip_revision);
  1350. schizo_pbm_hw_init(pbm);
  1351. pci_determine_mem_io_space(pbm);
  1352. ino_bitmap = of_get_property(dp, "ino-bitmap", NULL);
  1353. pbm->ino_bitmap = (((u64)ino_bitmap[1] << 32UL) |
  1354. ((u64)ino_bitmap[0] << 0UL));
  1355. busrange = of_get_property(dp, "bus-range", NULL);
  1356. pbm->pci_first_busno = busrange[0];
  1357. pbm->pci_last_busno = busrange[1];
  1358. schizo_pbm_iommu_init(pbm);
  1359. schizo_pbm_strbuf_init(pbm);
  1360. }
  1361. static inline int portid_compare(u32 x, u32 y, int chip_type)
  1362. {
  1363. if (chip_type == PBM_CHIP_TYPE_TOMATILLO) {
  1364. if (x == (y ^ 1))
  1365. return 1;
  1366. return 0;
  1367. }
  1368. return (x == y);
  1369. }
  1370. static void __schizo_init(struct device_node *dp, char *model_name, int chip_type)
  1371. {
  1372. struct pci_controller_info *p;
  1373. struct iommu *iommu;
  1374. u32 portid;
  1375. portid = of_getintprop_default(dp, "portid", 0xff);
  1376. for (p = pci_controller_root; p; p = p->next) {
  1377. struct pci_pbm_info *pbm;
  1378. if (p->pbm_A.prom_node && p->pbm_B.prom_node)
  1379. continue;
  1380. pbm = (p->pbm_A.prom_node ?
  1381. &p->pbm_A :
  1382. &p->pbm_B);
  1383. if (portid_compare(pbm->portid, portid, chip_type)) {
  1384. schizo_pbm_init(p, dp, portid, chip_type);
  1385. return;
  1386. }
  1387. }
  1388. p = kzalloc(sizeof(struct pci_controller_info), GFP_ATOMIC);
  1389. if (!p)
  1390. goto memfail;
  1391. iommu = kzalloc(sizeof(struct iommu), GFP_ATOMIC);
  1392. if (!iommu)
  1393. goto memfail;
  1394. p->pbm_A.iommu = iommu;
  1395. iommu = kzalloc(sizeof(struct iommu), GFP_ATOMIC);
  1396. if (!iommu)
  1397. goto memfail;
  1398. p->pbm_B.iommu = iommu;
  1399. p->next = pci_controller_root;
  1400. pci_controller_root = p;
  1401. p->index = pci_num_controllers++;
  1402. p->scan_bus = schizo_scan_bus;
  1403. p->pci_ops = &schizo_ops;
  1404. /* Like PSYCHO we have a 2GB aligned area for memory space. */
  1405. pci_memspace_mask = 0x7fffffffUL;
  1406. schizo_pbm_init(p, dp, portid, chip_type);
  1407. return;
  1408. memfail:
  1409. prom_printf("SCHIZO: Fatal memory allocation error.\n");
  1410. prom_halt();
  1411. }
  1412. void schizo_init(struct device_node *dp, char *model_name)
  1413. {
  1414. __schizo_init(dp, model_name, PBM_CHIP_TYPE_SCHIZO);
  1415. }
  1416. void schizo_plus_init(struct device_node *dp, char *model_name)
  1417. {
  1418. __schizo_init(dp, model_name, PBM_CHIP_TYPE_SCHIZO_PLUS);
  1419. }
  1420. void tomatillo_init(struct device_node *dp, char *model_name)
  1421. {
  1422. __schizo_init(dp, model_name, PBM_CHIP_TYPE_TOMATILLO);
  1423. }