pci_schizo.c 48 KB

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