pci_schizo.c 56 KB

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