pci_schizo.c 49 KB

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