pci_schizo.c 63 KB

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