pci_schizo.c 53 KB

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