pci_schizo.c 50 KB

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