pci_schizo.c 48 KB

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