pci_schizo.c 57 KB

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