pci_schizo.c 68 KB

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