pci_schizo.c 48 KB

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