pci_schizo.c 48 KB

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