pci_schizo.c 64 KB

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