pci_psycho.c 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449
  1. /* $Id: pci_psycho.c,v 1.33 2002/02/01 00:58:33 davem Exp $
  2. * pci_psycho.c: PSYCHO/U2P specific PCI controller support.
  3. *
  4. * Copyright (C) 1997, 1998, 1999 David S. Miller (davem@caipfs.rutgers.edu)
  5. * Copyright (C) 1998, 1999 Eddie C. Dost (ecd@skynet.be)
  6. * Copyright (C) 1999 Jakub Jelinek (jakub@redhat.com)
  7. */
  8. #include <linux/kernel.h>
  9. #include <linux/types.h>
  10. #include <linux/pci.h>
  11. #include <linux/init.h>
  12. #include <linux/slab.h>
  13. #include <linux/interrupt.h>
  14. #include <asm/pbm.h>
  15. #include <asm/iommu.h>
  16. #include <asm/irq.h>
  17. #include <asm/starfire.h>
  18. #include "pci_impl.h"
  19. #include "iommu_common.h"
  20. /* All PSYCHO registers are 64-bits. The following accessor
  21. * routines are how they are accessed. The REG parameter
  22. * is a physical address.
  23. */
  24. #define psycho_read(__reg) \
  25. ({ u64 __ret; \
  26. __asm__ __volatile__("ldxa [%1] %2, %0" \
  27. : "=r" (__ret) \
  28. : "r" (__reg), "i" (ASI_PHYS_BYPASS_EC_E) \
  29. : "memory"); \
  30. __ret; \
  31. })
  32. #define psycho_write(__reg, __val) \
  33. __asm__ __volatile__("stxa %0, [%1] %2" \
  34. : /* no outputs */ \
  35. : "r" (__val), "r" (__reg), \
  36. "i" (ASI_PHYS_BYPASS_EC_E) \
  37. : "memory")
  38. /* Misc. PSYCHO PCI controller register offsets and definitions. */
  39. #define PSYCHO_CONTROL 0x0010UL
  40. #define PSYCHO_CONTROL_IMPL 0xf000000000000000UL /* Implementation of this PSYCHO*/
  41. #define PSYCHO_CONTROL_VER 0x0f00000000000000UL /* Version of this PSYCHO */
  42. #define PSYCHO_CONTROL_MID 0x00f8000000000000UL /* UPA Module ID of PSYCHO */
  43. #define PSYCHO_CONTROL_IGN 0x0007c00000000000UL /* Interrupt Group Number */
  44. #define PSYCHO_CONTROL_RESV 0x00003ffffffffff0UL /* Reserved */
  45. #define PSYCHO_CONTROL_APCKEN 0x0000000000000008UL /* Address Parity Check Enable */
  46. #define PSYCHO_CONTROL_APERR 0x0000000000000004UL /* Incoming System Addr Parerr */
  47. #define PSYCHO_CONTROL_IAP 0x0000000000000002UL /* Invert UPA Parity */
  48. #define PSYCHO_CONTROL_MODE 0x0000000000000001UL /* PSYCHO clock mode */
  49. #define PSYCHO_PCIA_CTRL 0x2000UL
  50. #define PSYCHO_PCIB_CTRL 0x4000UL
  51. #define PSYCHO_PCICTRL_RESV1 0xfffffff000000000UL /* Reserved */
  52. #define PSYCHO_PCICTRL_SBH_ERR 0x0000000800000000UL /* Streaming byte hole error */
  53. #define PSYCHO_PCICTRL_SERR 0x0000000400000000UL /* SERR signal asserted */
  54. #define PSYCHO_PCICTRL_SPEED 0x0000000200000000UL /* PCI speed (1 is U2P clock) */
  55. #define PSYCHO_PCICTRL_RESV2 0x00000001ffc00000UL /* Reserved */
  56. #define PSYCHO_PCICTRL_ARB_PARK 0x0000000000200000UL /* PCI arbitration parking */
  57. #define PSYCHO_PCICTRL_RESV3 0x00000000001ff800UL /* Reserved */
  58. #define PSYCHO_PCICTRL_SBH_INT 0x0000000000000400UL /* Streaming byte hole int enab */
  59. #define PSYCHO_PCICTRL_WEN 0x0000000000000200UL /* Power Mgmt Wake Enable */
  60. #define PSYCHO_PCICTRL_EEN 0x0000000000000100UL /* PCI Error Interrupt Enable */
  61. #define PSYCHO_PCICTRL_RESV4 0x00000000000000c0UL /* Reserved */
  62. #define PSYCHO_PCICTRL_AEN 0x000000000000003fUL /* PCI DVMA Arbitration Enable */
  63. /* U2P Programmer's Manual, page 13-55, configuration space
  64. * address format:
  65. *
  66. * 32 24 23 16 15 11 10 8 7 2 1 0
  67. * ---------------------------------------------------------
  68. * |0 0 0 0 0 0 0 0 1| bus | device | function | reg | 0 0 |
  69. * ---------------------------------------------------------
  70. */
  71. #define PSYCHO_CONFIG_BASE(PBM) \
  72. ((PBM)->config_space | (1UL << 24))
  73. #define PSYCHO_CONFIG_ENCODE(BUS, DEVFN, REG) \
  74. (((unsigned long)(BUS) << 16) | \
  75. ((unsigned long)(DEVFN) << 8) | \
  76. ((unsigned long)(REG)))
  77. static void *psycho_pci_config_mkaddr(struct pci_pbm_info *pbm,
  78. unsigned char bus,
  79. unsigned int devfn,
  80. int where)
  81. {
  82. if (!pbm)
  83. return NULL;
  84. return (void *)
  85. (PSYCHO_CONFIG_BASE(pbm) |
  86. PSYCHO_CONFIG_ENCODE(bus, devfn, where));
  87. }
  88. static int psycho_out_of_range(struct pci_pbm_info *pbm,
  89. unsigned char bus,
  90. unsigned char devfn)
  91. {
  92. return ((pbm->parent == 0) ||
  93. ((pbm == &pbm->parent->pbm_B) &&
  94. (bus == pbm->pci_first_busno) &&
  95. PCI_SLOT(devfn) > 8) ||
  96. ((pbm == &pbm->parent->pbm_A) &&
  97. (bus == pbm->pci_first_busno) &&
  98. PCI_SLOT(devfn) > 8));
  99. }
  100. /* PSYCHO PCI configuration space accessors. */
  101. static int psycho_read_pci_cfg(struct pci_bus *bus_dev, unsigned int devfn,
  102. int where, int size, u32 *value)
  103. {
  104. struct pci_pbm_info *pbm = bus_dev->sysdata;
  105. unsigned char bus = bus_dev->number;
  106. u32 *addr;
  107. u16 tmp16;
  108. u8 tmp8;
  109. switch (size) {
  110. case 1:
  111. *value = 0xff;
  112. break;
  113. case 2:
  114. *value = 0xffff;
  115. break;
  116. case 4:
  117. *value = 0xffffffff;
  118. break;
  119. }
  120. addr = psycho_pci_config_mkaddr(pbm, bus, devfn, where);
  121. if (!addr)
  122. return PCIBIOS_SUCCESSFUL;
  123. if (psycho_out_of_range(pbm, bus, devfn))
  124. return PCIBIOS_SUCCESSFUL;
  125. switch (size) {
  126. case 1:
  127. pci_config_read8((u8 *)addr, &tmp8);
  128. *value = (u32) tmp8;
  129. break;
  130. case 2:
  131. if (where & 0x01) {
  132. printk("pci_read_config_word: misaligned reg [%x]\n",
  133. where);
  134. return PCIBIOS_SUCCESSFUL;
  135. }
  136. pci_config_read16((u16 *)addr, &tmp16);
  137. *value = (u32) tmp16;
  138. break;
  139. case 4:
  140. if (where & 0x03) {
  141. printk("pci_read_config_dword: misaligned reg [%x]\n",
  142. where);
  143. return PCIBIOS_SUCCESSFUL;
  144. }
  145. pci_config_read32(addr, value);
  146. break;
  147. }
  148. return PCIBIOS_SUCCESSFUL;
  149. }
  150. static int psycho_write_pci_cfg(struct pci_bus *bus_dev, unsigned int devfn,
  151. int where, int size, u32 value)
  152. {
  153. struct pci_pbm_info *pbm = bus_dev->sysdata;
  154. unsigned char bus = bus_dev->number;
  155. u32 *addr;
  156. addr = psycho_pci_config_mkaddr(pbm, bus, devfn, where);
  157. if (!addr)
  158. return PCIBIOS_SUCCESSFUL;
  159. if (psycho_out_of_range(pbm, bus, devfn))
  160. return PCIBIOS_SUCCESSFUL;
  161. switch (size) {
  162. case 1:
  163. pci_config_write8((u8 *)addr, value);
  164. break;
  165. case 2:
  166. if (where & 0x01) {
  167. printk("pci_write_config_word: misaligned reg [%x]\n",
  168. where);
  169. return PCIBIOS_SUCCESSFUL;
  170. }
  171. pci_config_write16((u16 *)addr, value);
  172. break;
  173. case 4:
  174. if (where & 0x03) {
  175. printk("pci_write_config_dword: misaligned reg [%x]\n",
  176. where);
  177. return PCIBIOS_SUCCESSFUL;
  178. }
  179. pci_config_write32(addr, value);
  180. }
  181. return PCIBIOS_SUCCESSFUL;
  182. }
  183. static struct pci_ops psycho_ops = {
  184. .read = psycho_read_pci_cfg,
  185. .write = psycho_write_pci_cfg,
  186. };
  187. /* PSYCHO interrupt mapping support. */
  188. #define PSYCHO_IMAP_A_SLOT0 0x0c00UL
  189. #define PSYCHO_IMAP_B_SLOT0 0x0c20UL
  190. static unsigned long psycho_pcislot_imap_offset(unsigned long ino)
  191. {
  192. unsigned int bus = (ino & 0x10) >> 4;
  193. unsigned int slot = (ino & 0x0c) >> 2;
  194. if (bus == 0)
  195. return PSYCHO_IMAP_A_SLOT0 + (slot * 8);
  196. else
  197. return PSYCHO_IMAP_B_SLOT0 + (slot * 8);
  198. }
  199. #define PSYCHO_IMAP_SCSI 0x1000UL
  200. #define PSYCHO_IMAP_ETH 0x1008UL
  201. #define PSYCHO_IMAP_BPP 0x1010UL
  202. #define PSYCHO_IMAP_AU_REC 0x1018UL
  203. #define PSYCHO_IMAP_AU_PLAY 0x1020UL
  204. #define PSYCHO_IMAP_PFAIL 0x1028UL
  205. #define PSYCHO_IMAP_KMS 0x1030UL
  206. #define PSYCHO_IMAP_FLPY 0x1038UL
  207. #define PSYCHO_IMAP_SHW 0x1040UL
  208. #define PSYCHO_IMAP_KBD 0x1048UL
  209. #define PSYCHO_IMAP_MS 0x1050UL
  210. #define PSYCHO_IMAP_SER 0x1058UL
  211. #define PSYCHO_IMAP_TIM0 0x1060UL
  212. #define PSYCHO_IMAP_TIM1 0x1068UL
  213. #define PSYCHO_IMAP_UE 0x1070UL
  214. #define PSYCHO_IMAP_CE 0x1078UL
  215. #define PSYCHO_IMAP_A_ERR 0x1080UL
  216. #define PSYCHO_IMAP_B_ERR 0x1088UL
  217. #define PSYCHO_IMAP_PMGMT 0x1090UL
  218. #define PSYCHO_IMAP_GFX 0x1098UL
  219. #define PSYCHO_IMAP_EUPA 0x10a0UL
  220. static unsigned long __onboard_imap_off[] = {
  221. /*0x20*/ PSYCHO_IMAP_SCSI,
  222. /*0x21*/ PSYCHO_IMAP_ETH,
  223. /*0x22*/ PSYCHO_IMAP_BPP,
  224. /*0x23*/ PSYCHO_IMAP_AU_REC,
  225. /*0x24*/ PSYCHO_IMAP_AU_PLAY,
  226. /*0x25*/ PSYCHO_IMAP_PFAIL,
  227. /*0x26*/ PSYCHO_IMAP_KMS,
  228. /*0x27*/ PSYCHO_IMAP_FLPY,
  229. /*0x28*/ PSYCHO_IMAP_SHW,
  230. /*0x29*/ PSYCHO_IMAP_KBD,
  231. /*0x2a*/ PSYCHO_IMAP_MS,
  232. /*0x2b*/ PSYCHO_IMAP_SER,
  233. /*0x2c*/ PSYCHO_IMAP_TIM0,
  234. /*0x2d*/ PSYCHO_IMAP_TIM1,
  235. /*0x2e*/ PSYCHO_IMAP_UE,
  236. /*0x2f*/ PSYCHO_IMAP_CE,
  237. /*0x30*/ PSYCHO_IMAP_A_ERR,
  238. /*0x31*/ PSYCHO_IMAP_B_ERR,
  239. /*0x32*/ PSYCHO_IMAP_PMGMT
  240. };
  241. #define PSYCHO_ONBOARD_IRQ_BASE 0x20
  242. #define PSYCHO_ONBOARD_IRQ_LAST 0x32
  243. #define psycho_onboard_imap_offset(__ino) \
  244. __onboard_imap_off[(__ino) - PSYCHO_ONBOARD_IRQ_BASE]
  245. #define PSYCHO_ICLR_A_SLOT0 0x1400UL
  246. #define PSYCHO_ICLR_SCSI 0x1800UL
  247. #define psycho_iclr_offset(ino) \
  248. ((ino & 0x20) ? (PSYCHO_ICLR_SCSI + (((ino) & 0x1f) << 3)) : \
  249. (PSYCHO_ICLR_A_SLOT0 + (((ino) & 0x1f)<<3)))
  250. static unsigned int psycho_irq_build(struct pci_pbm_info *pbm,
  251. struct pci_dev *pdev,
  252. unsigned int ino)
  253. {
  254. struct ino_bucket *bucket;
  255. unsigned long imap, iclr;
  256. unsigned long imap_off, iclr_off;
  257. int inofixup = 0;
  258. ino &= PCI_IRQ_INO;
  259. if (ino < PSYCHO_ONBOARD_IRQ_BASE) {
  260. /* PCI slot */
  261. imap_off = psycho_pcislot_imap_offset(ino);
  262. } else {
  263. /* Onboard device */
  264. if (ino > PSYCHO_ONBOARD_IRQ_LAST) {
  265. prom_printf("psycho_irq_build: Wacky INO [%x]\n", ino);
  266. prom_halt();
  267. }
  268. imap_off = psycho_onboard_imap_offset(ino);
  269. }
  270. /* Now build the IRQ bucket. */
  271. imap = pbm->controller_regs + imap_off;
  272. imap += 4;
  273. iclr_off = psycho_iclr_offset(ino);
  274. iclr = pbm->controller_regs + iclr_off;
  275. iclr += 4;
  276. if ((ino & 0x20) == 0)
  277. inofixup = ino & 0x03;
  278. bucket = __bucket(build_irq(inofixup, iclr, imap));
  279. bucket->flags |= IBF_PCI;
  280. return __irq(bucket);
  281. }
  282. /* PSYCHO error handling support. */
  283. enum psycho_error_type {
  284. UE_ERR, CE_ERR, PCI_ERR
  285. };
  286. /* Helper function of IOMMU error checking, which checks out
  287. * the state of the streaming buffers. The IOMMU lock is
  288. * held when this is called.
  289. *
  290. * For the PCI error case we know which PBM (and thus which
  291. * streaming buffer) caused the error, but for the uncorrectable
  292. * error case we do not. So we always check both streaming caches.
  293. */
  294. #define PSYCHO_STRBUF_CONTROL_A 0x2800UL
  295. #define PSYCHO_STRBUF_CONTROL_B 0x4800UL
  296. #define PSYCHO_STRBUF_CTRL_LPTR 0x00000000000000f0UL /* LRU Lock Pointer */
  297. #define PSYCHO_STRBUF_CTRL_LENAB 0x0000000000000008UL /* LRU Lock Enable */
  298. #define PSYCHO_STRBUF_CTRL_RRDIS 0x0000000000000004UL /* Rerun Disable */
  299. #define PSYCHO_STRBUF_CTRL_DENAB 0x0000000000000002UL /* Diagnostic Mode Enable */
  300. #define PSYCHO_STRBUF_CTRL_ENAB 0x0000000000000001UL /* Streaming Buffer Enable */
  301. #define PSYCHO_STRBUF_FLUSH_A 0x2808UL
  302. #define PSYCHO_STRBUF_FLUSH_B 0x4808UL
  303. #define PSYCHO_STRBUF_FSYNC_A 0x2810UL
  304. #define PSYCHO_STRBUF_FSYNC_B 0x4810UL
  305. #define PSYCHO_STC_DATA_A 0xb000UL
  306. #define PSYCHO_STC_DATA_B 0xc000UL
  307. #define PSYCHO_STC_ERR_A 0xb400UL
  308. #define PSYCHO_STC_ERR_B 0xc400UL
  309. #define PSYCHO_STCERR_WRITE 0x0000000000000002UL /* Write Error */
  310. #define PSYCHO_STCERR_READ 0x0000000000000001UL /* Read Error */
  311. #define PSYCHO_STC_TAG_A 0xb800UL
  312. #define PSYCHO_STC_TAG_B 0xc800UL
  313. #define PSYCHO_STCTAG_PPN 0x0fffffff00000000UL /* Physical Page Number */
  314. #define PSYCHO_STCTAG_VPN 0x00000000ffffe000UL /* Virtual Page Number */
  315. #define PSYCHO_STCTAG_VALID 0x0000000000000002UL /* Valid */
  316. #define PSYCHO_STCTAG_WRITE 0x0000000000000001UL /* Writable */
  317. #define PSYCHO_STC_LINE_A 0xb900UL
  318. #define PSYCHO_STC_LINE_B 0xc900UL
  319. #define PSYCHO_STCLINE_LINDX 0x0000000001e00000UL /* LRU Index */
  320. #define PSYCHO_STCLINE_SPTR 0x00000000001f8000UL /* Dirty Data Start Pointer */
  321. #define PSYCHO_STCLINE_LADDR 0x0000000000007f00UL /* Line Address */
  322. #define PSYCHO_STCLINE_EPTR 0x00000000000000fcUL /* Dirty Data End Pointer */
  323. #define PSYCHO_STCLINE_VALID 0x0000000000000002UL /* Valid */
  324. #define PSYCHO_STCLINE_FOFN 0x0000000000000001UL /* Fetch Outstanding / Flush Necessary */
  325. static DEFINE_SPINLOCK(stc_buf_lock);
  326. static unsigned long stc_error_buf[128];
  327. static unsigned long stc_tag_buf[16];
  328. static unsigned long stc_line_buf[16];
  329. static void __psycho_check_one_stc(struct pci_controller_info *p,
  330. struct pci_pbm_info *pbm,
  331. int is_pbm_a)
  332. {
  333. struct pci_strbuf *strbuf = &pbm->stc;
  334. unsigned long regbase = p->pbm_A.controller_regs;
  335. unsigned long err_base, tag_base, line_base;
  336. u64 control;
  337. int i;
  338. if (is_pbm_a) {
  339. err_base = regbase + PSYCHO_STC_ERR_A;
  340. tag_base = regbase + PSYCHO_STC_TAG_A;
  341. line_base = regbase + PSYCHO_STC_LINE_A;
  342. } else {
  343. err_base = regbase + PSYCHO_STC_ERR_B;
  344. tag_base = regbase + PSYCHO_STC_TAG_B;
  345. line_base = regbase + PSYCHO_STC_LINE_B;
  346. }
  347. spin_lock(&stc_buf_lock);
  348. /* This is __REALLY__ dangerous. When we put the
  349. * streaming buffer into diagnostic mode to probe
  350. * it's tags and error status, we _must_ clear all
  351. * of the line tag valid bits before re-enabling
  352. * the streaming buffer. If any dirty data lives
  353. * in the STC when we do this, we will end up
  354. * invalidating it before it has a chance to reach
  355. * main memory.
  356. */
  357. control = psycho_read(strbuf->strbuf_control);
  358. psycho_write(strbuf->strbuf_control,
  359. (control | PSYCHO_STRBUF_CTRL_DENAB));
  360. for (i = 0; i < 128; i++) {
  361. unsigned long val;
  362. val = psycho_read(err_base + (i * 8UL));
  363. psycho_write(err_base + (i * 8UL), 0UL);
  364. stc_error_buf[i] = val;
  365. }
  366. for (i = 0; i < 16; i++) {
  367. stc_tag_buf[i] = psycho_read(tag_base + (i * 8UL));
  368. stc_line_buf[i] = psycho_read(line_base + (i * 8UL));
  369. psycho_write(tag_base + (i * 8UL), 0UL);
  370. psycho_write(line_base + (i * 8UL), 0UL);
  371. }
  372. /* OK, state is logged, exit diagnostic mode. */
  373. psycho_write(strbuf->strbuf_control, control);
  374. for (i = 0; i < 16; i++) {
  375. int j, saw_error, first, last;
  376. saw_error = 0;
  377. first = i * 8;
  378. last = first + 8;
  379. for (j = first; j < last; j++) {
  380. unsigned long errval = stc_error_buf[j];
  381. if (errval != 0) {
  382. saw_error++;
  383. printk("PSYCHO%d(PBM%c): STC_ERR(%d)[wr(%d)rd(%d)]\n",
  384. p->index,
  385. (is_pbm_a ? 'A' : 'B'),
  386. j,
  387. (errval & PSYCHO_STCERR_WRITE) ? 1 : 0,
  388. (errval & PSYCHO_STCERR_READ) ? 1 : 0);
  389. }
  390. }
  391. if (saw_error != 0) {
  392. unsigned long tagval = stc_tag_buf[i];
  393. unsigned long lineval = stc_line_buf[i];
  394. printk("PSYCHO%d(PBM%c): STC_TAG(%d)[PA(%016lx)VA(%08lx)V(%d)W(%d)]\n",
  395. p->index,
  396. (is_pbm_a ? 'A' : 'B'),
  397. i,
  398. ((tagval & PSYCHO_STCTAG_PPN) >> 19UL),
  399. (tagval & PSYCHO_STCTAG_VPN),
  400. ((tagval & PSYCHO_STCTAG_VALID) ? 1 : 0),
  401. ((tagval & PSYCHO_STCTAG_WRITE) ? 1 : 0));
  402. printk("PSYCHO%d(PBM%c): STC_LINE(%d)[LIDX(%lx)SP(%lx)LADDR(%lx)EP(%lx)"
  403. "V(%d)FOFN(%d)]\n",
  404. p->index,
  405. (is_pbm_a ? 'A' : 'B'),
  406. i,
  407. ((lineval & PSYCHO_STCLINE_LINDX) >> 21UL),
  408. ((lineval & PSYCHO_STCLINE_SPTR) >> 15UL),
  409. ((lineval & PSYCHO_STCLINE_LADDR) >> 8UL),
  410. ((lineval & PSYCHO_STCLINE_EPTR) >> 2UL),
  411. ((lineval & PSYCHO_STCLINE_VALID) ? 1 : 0),
  412. ((lineval & PSYCHO_STCLINE_FOFN) ? 1 : 0));
  413. }
  414. }
  415. spin_unlock(&stc_buf_lock);
  416. }
  417. static void __psycho_check_stc_error(struct pci_controller_info *p,
  418. unsigned long afsr,
  419. unsigned long afar,
  420. enum psycho_error_type type)
  421. {
  422. struct pci_pbm_info *pbm;
  423. pbm = &p->pbm_A;
  424. if (pbm->stc.strbuf_enabled)
  425. __psycho_check_one_stc(p, pbm, 1);
  426. pbm = &p->pbm_B;
  427. if (pbm->stc.strbuf_enabled)
  428. __psycho_check_one_stc(p, pbm, 0);
  429. }
  430. /* When an Uncorrectable Error or a PCI Error happens, we
  431. * interrogate the IOMMU state to see if it is the cause.
  432. */
  433. #define PSYCHO_IOMMU_CONTROL 0x0200UL
  434. #define PSYCHO_IOMMU_CTRL_RESV 0xfffffffff9000000UL /* Reserved */
  435. #define PSYCHO_IOMMU_CTRL_XLTESTAT 0x0000000006000000UL /* Translation Error Status */
  436. #define PSYCHO_IOMMU_CTRL_XLTEERR 0x0000000001000000UL /* Translation Error encountered */
  437. #define PSYCHO_IOMMU_CTRL_LCKEN 0x0000000000800000UL /* Enable translation locking */
  438. #define PSYCHO_IOMMU_CTRL_LCKPTR 0x0000000000780000UL /* Translation lock pointer */
  439. #define PSYCHO_IOMMU_CTRL_TSBSZ 0x0000000000070000UL /* TSB Size */
  440. #define PSYCHO_IOMMU_TSBSZ_1K 0x0000000000000000UL /* TSB Table 1024 8-byte entries */
  441. #define PSYCHO_IOMMU_TSBSZ_2K 0x0000000000010000UL /* TSB Table 2048 8-byte entries */
  442. #define PSYCHO_IOMMU_TSBSZ_4K 0x0000000000020000UL /* TSB Table 4096 8-byte entries */
  443. #define PSYCHO_IOMMU_TSBSZ_8K 0x0000000000030000UL /* TSB Table 8192 8-byte entries */
  444. #define PSYCHO_IOMMU_TSBSZ_16K 0x0000000000040000UL /* TSB Table 16k 8-byte entries */
  445. #define PSYCHO_IOMMU_TSBSZ_32K 0x0000000000050000UL /* TSB Table 32k 8-byte entries */
  446. #define PSYCHO_IOMMU_TSBSZ_64K 0x0000000000060000UL /* TSB Table 64k 8-byte entries */
  447. #define PSYCHO_IOMMU_TSBSZ_128K 0x0000000000070000UL /* TSB Table 128k 8-byte entries */
  448. #define PSYCHO_IOMMU_CTRL_RESV2 0x000000000000fff8UL /* Reserved */
  449. #define PSYCHO_IOMMU_CTRL_TBWSZ 0x0000000000000004UL /* Assumed page size, 0=8k 1=64k */
  450. #define PSYCHO_IOMMU_CTRL_DENAB 0x0000000000000002UL /* Diagnostic mode enable */
  451. #define PSYCHO_IOMMU_CTRL_ENAB 0x0000000000000001UL /* IOMMU Enable */
  452. #define PSYCHO_IOMMU_TSBBASE 0x0208UL
  453. #define PSYCHO_IOMMU_FLUSH 0x0210UL
  454. #define PSYCHO_IOMMU_TAG 0xa580UL
  455. #define PSYCHO_IOMMU_TAG_ERRSTS (0x3UL << 23UL)
  456. #define PSYCHO_IOMMU_TAG_ERR (0x1UL << 22UL)
  457. #define PSYCHO_IOMMU_TAG_WRITE (0x1UL << 21UL)
  458. #define PSYCHO_IOMMU_TAG_STREAM (0x1UL << 20UL)
  459. #define PSYCHO_IOMMU_TAG_SIZE (0x1UL << 19UL)
  460. #define PSYCHO_IOMMU_TAG_VPAGE 0x7ffffUL
  461. #define PSYCHO_IOMMU_DATA 0xa600UL
  462. #define PSYCHO_IOMMU_DATA_VALID (1UL << 30UL)
  463. #define PSYCHO_IOMMU_DATA_CACHE (1UL << 28UL)
  464. #define PSYCHO_IOMMU_DATA_PPAGE 0xfffffffUL
  465. static void psycho_check_iommu_error(struct pci_controller_info *p,
  466. unsigned long afsr,
  467. unsigned long afar,
  468. enum psycho_error_type type)
  469. {
  470. struct pci_iommu *iommu = p->pbm_A.iommu;
  471. unsigned long iommu_tag[16];
  472. unsigned long iommu_data[16];
  473. unsigned long flags;
  474. u64 control;
  475. int i;
  476. spin_lock_irqsave(&iommu->lock, flags);
  477. control = psycho_read(iommu->iommu_control);
  478. if (control & PSYCHO_IOMMU_CTRL_XLTEERR) {
  479. char *type_string;
  480. /* Clear the error encountered bit. */
  481. control &= ~PSYCHO_IOMMU_CTRL_XLTEERR;
  482. psycho_write(iommu->iommu_control, control);
  483. switch((control & PSYCHO_IOMMU_CTRL_XLTESTAT) >> 25UL) {
  484. case 0:
  485. type_string = "Protection Error";
  486. break;
  487. case 1:
  488. type_string = "Invalid Error";
  489. break;
  490. case 2:
  491. type_string = "TimeOut Error";
  492. break;
  493. case 3:
  494. default:
  495. type_string = "ECC Error";
  496. break;
  497. };
  498. printk("PSYCHO%d: IOMMU Error, type[%s]\n",
  499. p->index, type_string);
  500. /* Put the IOMMU into diagnostic mode and probe
  501. * it's TLB for entries with error status.
  502. *
  503. * It is very possible for another DVMA to occur
  504. * while we do this probe, and corrupt the system
  505. * further. But we are so screwed at this point
  506. * that we are likely to crash hard anyways, so
  507. * get as much diagnostic information to the
  508. * console as we can.
  509. */
  510. psycho_write(iommu->iommu_control,
  511. control | PSYCHO_IOMMU_CTRL_DENAB);
  512. for (i = 0; i < 16; i++) {
  513. unsigned long base = p->pbm_A.controller_regs;
  514. iommu_tag[i] =
  515. psycho_read(base + PSYCHO_IOMMU_TAG + (i * 8UL));
  516. iommu_data[i] =
  517. psycho_read(base + PSYCHO_IOMMU_DATA + (i * 8UL));
  518. /* Now clear out the entry. */
  519. psycho_write(base + PSYCHO_IOMMU_TAG + (i * 8UL), 0);
  520. psycho_write(base + PSYCHO_IOMMU_DATA + (i * 8UL), 0);
  521. }
  522. /* Leave diagnostic mode. */
  523. psycho_write(iommu->iommu_control, control);
  524. for (i = 0; i < 16; i++) {
  525. unsigned long tag, data;
  526. tag = iommu_tag[i];
  527. if (!(tag & PSYCHO_IOMMU_TAG_ERR))
  528. continue;
  529. data = iommu_data[i];
  530. switch((tag & PSYCHO_IOMMU_TAG_ERRSTS) >> 23UL) {
  531. case 0:
  532. type_string = "Protection Error";
  533. break;
  534. case 1:
  535. type_string = "Invalid Error";
  536. break;
  537. case 2:
  538. type_string = "TimeOut Error";
  539. break;
  540. case 3:
  541. default:
  542. type_string = "ECC Error";
  543. break;
  544. };
  545. printk("PSYCHO%d: IOMMU TAG(%d)[error(%s) wr(%d) str(%d) sz(%dK) vpg(%08lx)]\n",
  546. p->index, i, type_string,
  547. ((tag & PSYCHO_IOMMU_TAG_WRITE) ? 1 : 0),
  548. ((tag & PSYCHO_IOMMU_TAG_STREAM) ? 1 : 0),
  549. ((tag & PSYCHO_IOMMU_TAG_SIZE) ? 64 : 8),
  550. (tag & PSYCHO_IOMMU_TAG_VPAGE) << IOMMU_PAGE_SHIFT);
  551. printk("PSYCHO%d: IOMMU DATA(%d)[valid(%d) cache(%d) ppg(%016lx)]\n",
  552. p->index, i,
  553. ((data & PSYCHO_IOMMU_DATA_VALID) ? 1 : 0),
  554. ((data & PSYCHO_IOMMU_DATA_CACHE) ? 1 : 0),
  555. (data & PSYCHO_IOMMU_DATA_PPAGE) << IOMMU_PAGE_SHIFT);
  556. }
  557. }
  558. __psycho_check_stc_error(p, afsr, afar, type);
  559. spin_unlock_irqrestore(&iommu->lock, flags);
  560. }
  561. /* Uncorrectable Errors. Cause of the error and the address are
  562. * recorded in the UE_AFSR and UE_AFAR of PSYCHO. They are errors
  563. * relating to UPA interface transactions.
  564. */
  565. #define PSYCHO_UE_AFSR 0x0030UL
  566. #define PSYCHO_UEAFSR_PPIO 0x8000000000000000UL /* Primary PIO is cause */
  567. #define PSYCHO_UEAFSR_PDRD 0x4000000000000000UL /* Primary DVMA read is cause */
  568. #define PSYCHO_UEAFSR_PDWR 0x2000000000000000UL /* Primary DVMA write is cause */
  569. #define PSYCHO_UEAFSR_SPIO 0x1000000000000000UL /* Secondary PIO is cause */
  570. #define PSYCHO_UEAFSR_SDRD 0x0800000000000000UL /* Secondary DVMA read is cause */
  571. #define PSYCHO_UEAFSR_SDWR 0x0400000000000000UL /* Secondary DVMA write is cause*/
  572. #define PSYCHO_UEAFSR_RESV1 0x03ff000000000000UL /* Reserved */
  573. #define PSYCHO_UEAFSR_BMSK 0x0000ffff00000000UL /* Bytemask of failed transfer */
  574. #define PSYCHO_UEAFSR_DOFF 0x00000000e0000000UL /* Doubleword Offset */
  575. #define PSYCHO_UEAFSR_MID 0x000000001f000000UL /* UPA MID causing the fault */
  576. #define PSYCHO_UEAFSR_BLK 0x0000000000800000UL /* Trans was block operation */
  577. #define PSYCHO_UEAFSR_RESV2 0x00000000007fffffUL /* Reserved */
  578. #define PSYCHO_UE_AFAR 0x0038UL
  579. static irqreturn_t psycho_ue_intr(int irq, void *dev_id, struct pt_regs *regs)
  580. {
  581. struct pci_controller_info *p = dev_id;
  582. unsigned long afsr_reg = p->pbm_A.controller_regs + PSYCHO_UE_AFSR;
  583. unsigned long afar_reg = p->pbm_A.controller_regs + PSYCHO_UE_AFAR;
  584. unsigned long afsr, afar, error_bits;
  585. int reported;
  586. /* Latch uncorrectable error status. */
  587. afar = psycho_read(afar_reg);
  588. afsr = psycho_read(afsr_reg);
  589. /* Clear the primary/secondary error status bits. */
  590. error_bits = afsr &
  591. (PSYCHO_UEAFSR_PPIO | PSYCHO_UEAFSR_PDRD | PSYCHO_UEAFSR_PDWR |
  592. PSYCHO_UEAFSR_SPIO | PSYCHO_UEAFSR_SDRD | PSYCHO_UEAFSR_SDWR);
  593. if (!error_bits)
  594. return IRQ_NONE;
  595. psycho_write(afsr_reg, error_bits);
  596. /* Log the error. */
  597. printk("PSYCHO%d: Uncorrectable Error, primary error type[%s]\n",
  598. p->index,
  599. (((error_bits & PSYCHO_UEAFSR_PPIO) ?
  600. "PIO" :
  601. ((error_bits & PSYCHO_UEAFSR_PDRD) ?
  602. "DMA Read" :
  603. ((error_bits & PSYCHO_UEAFSR_PDWR) ?
  604. "DMA Write" : "???")))));
  605. printk("PSYCHO%d: bytemask[%04lx] dword_offset[%lx] UPA_MID[%02lx] was_block(%d)\n",
  606. p->index,
  607. (afsr & PSYCHO_UEAFSR_BMSK) >> 32UL,
  608. (afsr & PSYCHO_UEAFSR_DOFF) >> 29UL,
  609. (afsr & PSYCHO_UEAFSR_MID) >> 24UL,
  610. ((afsr & PSYCHO_UEAFSR_BLK) ? 1 : 0));
  611. printk("PSYCHO%d: UE AFAR [%016lx]\n", p->index, afar);
  612. printk("PSYCHO%d: UE Secondary errors [", p->index);
  613. reported = 0;
  614. if (afsr & PSYCHO_UEAFSR_SPIO) {
  615. reported++;
  616. printk("(PIO)");
  617. }
  618. if (afsr & PSYCHO_UEAFSR_SDRD) {
  619. reported++;
  620. printk("(DMA Read)");
  621. }
  622. if (afsr & PSYCHO_UEAFSR_SDWR) {
  623. reported++;
  624. printk("(DMA Write)");
  625. }
  626. if (!reported)
  627. printk("(none)");
  628. printk("]\n");
  629. /* Interrogate IOMMU for error status. */
  630. psycho_check_iommu_error(p, afsr, afar, UE_ERR);
  631. return IRQ_HANDLED;
  632. }
  633. /* Correctable Errors. */
  634. #define PSYCHO_CE_AFSR 0x0040UL
  635. #define PSYCHO_CEAFSR_PPIO 0x8000000000000000UL /* Primary PIO is cause */
  636. #define PSYCHO_CEAFSR_PDRD 0x4000000000000000UL /* Primary DVMA read is cause */
  637. #define PSYCHO_CEAFSR_PDWR 0x2000000000000000UL /* Primary DVMA write is cause */
  638. #define PSYCHO_CEAFSR_SPIO 0x1000000000000000UL /* Secondary PIO is cause */
  639. #define PSYCHO_CEAFSR_SDRD 0x0800000000000000UL /* Secondary DVMA read is cause */
  640. #define PSYCHO_CEAFSR_SDWR 0x0400000000000000UL /* Secondary DVMA write is cause*/
  641. #define PSYCHO_CEAFSR_RESV1 0x0300000000000000UL /* Reserved */
  642. #define PSYCHO_CEAFSR_ESYND 0x00ff000000000000UL /* Syndrome Bits */
  643. #define PSYCHO_CEAFSR_BMSK 0x0000ffff00000000UL /* Bytemask of failed transfer */
  644. #define PSYCHO_CEAFSR_DOFF 0x00000000e0000000UL /* Double Offset */
  645. #define PSYCHO_CEAFSR_MID 0x000000001f000000UL /* UPA MID causing the fault */
  646. #define PSYCHO_CEAFSR_BLK 0x0000000000800000UL /* Trans was block operation */
  647. #define PSYCHO_CEAFSR_RESV2 0x00000000007fffffUL /* Reserved */
  648. #define PSYCHO_CE_AFAR 0x0040UL
  649. static irqreturn_t psycho_ce_intr(int irq, void *dev_id, struct pt_regs *regs)
  650. {
  651. struct pci_controller_info *p = dev_id;
  652. unsigned long afsr_reg = p->pbm_A.controller_regs + PSYCHO_CE_AFSR;
  653. unsigned long afar_reg = p->pbm_A.controller_regs + PSYCHO_CE_AFAR;
  654. unsigned long afsr, afar, error_bits;
  655. int reported;
  656. /* Latch error status. */
  657. afar = psycho_read(afar_reg);
  658. afsr = psycho_read(afsr_reg);
  659. /* Clear primary/secondary error status bits. */
  660. error_bits = afsr &
  661. (PSYCHO_CEAFSR_PPIO | PSYCHO_CEAFSR_PDRD | PSYCHO_CEAFSR_PDWR |
  662. PSYCHO_CEAFSR_SPIO | PSYCHO_CEAFSR_SDRD | PSYCHO_CEAFSR_SDWR);
  663. if (!error_bits)
  664. return IRQ_NONE;
  665. psycho_write(afsr_reg, error_bits);
  666. /* Log the error. */
  667. printk("PSYCHO%d: Correctable Error, primary error type[%s]\n",
  668. p->index,
  669. (((error_bits & PSYCHO_CEAFSR_PPIO) ?
  670. "PIO" :
  671. ((error_bits & PSYCHO_CEAFSR_PDRD) ?
  672. "DMA Read" :
  673. ((error_bits & PSYCHO_CEAFSR_PDWR) ?
  674. "DMA Write" : "???")))));
  675. /* XXX Use syndrome and afar to print out module string just like
  676. * XXX UDB CE trap handler does... -DaveM
  677. */
  678. printk("PSYCHO%d: syndrome[%02lx] bytemask[%04lx] dword_offset[%lx] "
  679. "UPA_MID[%02lx] was_block(%d)\n",
  680. p->index,
  681. (afsr & PSYCHO_CEAFSR_ESYND) >> 48UL,
  682. (afsr & PSYCHO_CEAFSR_BMSK) >> 32UL,
  683. (afsr & PSYCHO_CEAFSR_DOFF) >> 29UL,
  684. (afsr & PSYCHO_CEAFSR_MID) >> 24UL,
  685. ((afsr & PSYCHO_CEAFSR_BLK) ? 1 : 0));
  686. printk("PSYCHO%d: CE AFAR [%016lx]\n", p->index, afar);
  687. printk("PSYCHO%d: CE Secondary errors [", p->index);
  688. reported = 0;
  689. if (afsr & PSYCHO_CEAFSR_SPIO) {
  690. reported++;
  691. printk("(PIO)");
  692. }
  693. if (afsr & PSYCHO_CEAFSR_SDRD) {
  694. reported++;
  695. printk("(DMA Read)");
  696. }
  697. if (afsr & PSYCHO_CEAFSR_SDWR) {
  698. reported++;
  699. printk("(DMA Write)");
  700. }
  701. if (!reported)
  702. printk("(none)");
  703. printk("]\n");
  704. return IRQ_HANDLED;
  705. }
  706. /* PCI Errors. They are signalled by the PCI bus module since they
  707. * are associated with a specific bus segment.
  708. */
  709. #define PSYCHO_PCI_AFSR_A 0x2010UL
  710. #define PSYCHO_PCI_AFSR_B 0x4010UL
  711. #define PSYCHO_PCIAFSR_PMA 0x8000000000000000UL /* Primary Master Abort Error */
  712. #define PSYCHO_PCIAFSR_PTA 0x4000000000000000UL /* Primary Target Abort Error */
  713. #define PSYCHO_PCIAFSR_PRTRY 0x2000000000000000UL /* Primary Excessive Retries */
  714. #define PSYCHO_PCIAFSR_PPERR 0x1000000000000000UL /* Primary Parity Error */
  715. #define PSYCHO_PCIAFSR_SMA 0x0800000000000000UL /* Secondary Master Abort Error */
  716. #define PSYCHO_PCIAFSR_STA 0x0400000000000000UL /* Secondary Target Abort Error */
  717. #define PSYCHO_PCIAFSR_SRTRY 0x0200000000000000UL /* Secondary Excessive Retries */
  718. #define PSYCHO_PCIAFSR_SPERR 0x0100000000000000UL /* Secondary Parity Error */
  719. #define PSYCHO_PCIAFSR_RESV1 0x00ff000000000000UL /* Reserved */
  720. #define PSYCHO_PCIAFSR_BMSK 0x0000ffff00000000UL /* Bytemask of failed transfer */
  721. #define PSYCHO_PCIAFSR_BLK 0x0000000080000000UL /* Trans was block operation */
  722. #define PSYCHO_PCIAFSR_RESV2 0x0000000040000000UL /* Reserved */
  723. #define PSYCHO_PCIAFSR_MID 0x000000003e000000UL /* MID causing the error */
  724. #define PSYCHO_PCIAFSR_RESV3 0x0000000001ffffffUL /* Reserved */
  725. #define PSYCHO_PCI_AFAR_A 0x2018UL
  726. #define PSYCHO_PCI_AFAR_B 0x4018UL
  727. static irqreturn_t psycho_pcierr_intr_other(struct pci_pbm_info *pbm, int is_pbm_a)
  728. {
  729. unsigned long csr_reg, csr, csr_error_bits;
  730. irqreturn_t ret = IRQ_NONE;
  731. u16 stat;
  732. if (is_pbm_a) {
  733. csr_reg = pbm->controller_regs + PSYCHO_PCIA_CTRL;
  734. } else {
  735. csr_reg = pbm->controller_regs + PSYCHO_PCIB_CTRL;
  736. }
  737. csr = psycho_read(csr_reg);
  738. csr_error_bits =
  739. csr & (PSYCHO_PCICTRL_SBH_ERR | PSYCHO_PCICTRL_SERR);
  740. if (csr_error_bits) {
  741. /* Clear the errors. */
  742. psycho_write(csr_reg, csr);
  743. /* Log 'em. */
  744. if (csr_error_bits & PSYCHO_PCICTRL_SBH_ERR)
  745. printk("%s: PCI streaming byte hole error asserted.\n",
  746. pbm->name);
  747. if (csr_error_bits & PSYCHO_PCICTRL_SERR)
  748. printk("%s: PCI SERR signal asserted.\n", pbm->name);
  749. ret = IRQ_HANDLED;
  750. }
  751. pci_read_config_word(pbm->pci_bus->self, PCI_STATUS, &stat);
  752. if (stat & (PCI_STATUS_PARITY |
  753. PCI_STATUS_SIG_TARGET_ABORT |
  754. PCI_STATUS_REC_TARGET_ABORT |
  755. PCI_STATUS_REC_MASTER_ABORT |
  756. PCI_STATUS_SIG_SYSTEM_ERROR)) {
  757. printk("%s: PCI bus error, PCI_STATUS[%04x]\n",
  758. pbm->name, stat);
  759. pci_write_config_word(pbm->pci_bus->self, PCI_STATUS, 0xffff);
  760. ret = IRQ_HANDLED;
  761. }
  762. return ret;
  763. }
  764. static irqreturn_t psycho_pcierr_intr(int irq, void *dev_id, struct pt_regs *regs)
  765. {
  766. struct pci_pbm_info *pbm = dev_id;
  767. struct pci_controller_info *p = pbm->parent;
  768. unsigned long afsr_reg, afar_reg;
  769. unsigned long afsr, afar, error_bits;
  770. int is_pbm_a, reported;
  771. is_pbm_a = (pbm == &pbm->parent->pbm_A);
  772. if (is_pbm_a) {
  773. afsr_reg = p->pbm_A.controller_regs + PSYCHO_PCI_AFSR_A;
  774. afar_reg = p->pbm_A.controller_regs + PSYCHO_PCI_AFAR_A;
  775. } else {
  776. afsr_reg = p->pbm_A.controller_regs + PSYCHO_PCI_AFSR_B;
  777. afar_reg = p->pbm_A.controller_regs + PSYCHO_PCI_AFAR_B;
  778. }
  779. /* Latch error status. */
  780. afar = psycho_read(afar_reg);
  781. afsr = psycho_read(afsr_reg);
  782. /* Clear primary/secondary error status bits. */
  783. error_bits = afsr &
  784. (PSYCHO_PCIAFSR_PMA | PSYCHO_PCIAFSR_PTA |
  785. PSYCHO_PCIAFSR_PRTRY | PSYCHO_PCIAFSR_PPERR |
  786. PSYCHO_PCIAFSR_SMA | PSYCHO_PCIAFSR_STA |
  787. PSYCHO_PCIAFSR_SRTRY | PSYCHO_PCIAFSR_SPERR);
  788. if (!error_bits)
  789. return psycho_pcierr_intr_other(pbm, is_pbm_a);
  790. psycho_write(afsr_reg, error_bits);
  791. /* Log the error. */
  792. printk("PSYCHO%d(PBM%c): PCI Error, primary error type[%s]\n",
  793. p->index, (is_pbm_a ? 'A' : 'B'),
  794. (((error_bits & PSYCHO_PCIAFSR_PMA) ?
  795. "Master Abort" :
  796. ((error_bits & PSYCHO_PCIAFSR_PTA) ?
  797. "Target Abort" :
  798. ((error_bits & PSYCHO_PCIAFSR_PRTRY) ?
  799. "Excessive Retries" :
  800. ((error_bits & PSYCHO_PCIAFSR_PPERR) ?
  801. "Parity Error" : "???"))))));
  802. printk("PSYCHO%d(PBM%c): bytemask[%04lx] UPA_MID[%02lx] was_block(%d)\n",
  803. p->index, (is_pbm_a ? 'A' : 'B'),
  804. (afsr & PSYCHO_PCIAFSR_BMSK) >> 32UL,
  805. (afsr & PSYCHO_PCIAFSR_MID) >> 25UL,
  806. (afsr & PSYCHO_PCIAFSR_BLK) ? 1 : 0);
  807. printk("PSYCHO%d(PBM%c): PCI AFAR [%016lx]\n",
  808. p->index, (is_pbm_a ? 'A' : 'B'), afar);
  809. printk("PSYCHO%d(PBM%c): PCI Secondary errors [",
  810. p->index, (is_pbm_a ? 'A' : 'B'));
  811. reported = 0;
  812. if (afsr & PSYCHO_PCIAFSR_SMA) {
  813. reported++;
  814. printk("(Master Abort)");
  815. }
  816. if (afsr & PSYCHO_PCIAFSR_STA) {
  817. reported++;
  818. printk("(Target Abort)");
  819. }
  820. if (afsr & PSYCHO_PCIAFSR_SRTRY) {
  821. reported++;
  822. printk("(Excessive Retries)");
  823. }
  824. if (afsr & PSYCHO_PCIAFSR_SPERR) {
  825. reported++;
  826. printk("(Parity Error)");
  827. }
  828. if (!reported)
  829. printk("(none)");
  830. printk("]\n");
  831. /* For the error types shown, scan PBM's PCI bus for devices
  832. * which have logged that error type.
  833. */
  834. /* If we see a Target Abort, this could be the result of an
  835. * IOMMU translation error of some sort. It is extremely
  836. * useful to log this information as usually it indicates
  837. * a bug in the IOMMU support code or a PCI device driver.
  838. */
  839. if (error_bits & (PSYCHO_PCIAFSR_PTA | PSYCHO_PCIAFSR_STA)) {
  840. psycho_check_iommu_error(p, afsr, afar, PCI_ERR);
  841. pci_scan_for_target_abort(p, pbm, pbm->pci_bus);
  842. }
  843. if (error_bits & (PSYCHO_PCIAFSR_PMA | PSYCHO_PCIAFSR_SMA))
  844. pci_scan_for_master_abort(p, pbm, pbm->pci_bus);
  845. /* For excessive retries, PSYCHO/PBM will abort the device
  846. * and there is no way to specifically check for excessive
  847. * retries in the config space status registers. So what
  848. * we hope is that we'll catch it via the master/target
  849. * abort events.
  850. */
  851. if (error_bits & (PSYCHO_PCIAFSR_PPERR | PSYCHO_PCIAFSR_SPERR))
  852. pci_scan_for_parity_error(p, pbm, pbm->pci_bus);
  853. return IRQ_HANDLED;
  854. }
  855. /* XXX What about PowerFail/PowerManagement??? -DaveM */
  856. #define PSYCHO_ECC_CTRL 0x0020
  857. #define PSYCHO_ECCCTRL_EE 0x8000000000000000UL /* Enable ECC Checking */
  858. #define PSYCHO_ECCCTRL_UE 0x4000000000000000UL /* Enable UE Interrupts */
  859. #define PSYCHO_ECCCTRL_CE 0x2000000000000000UL /* Enable CE INterrupts */
  860. #define PSYCHO_UE_INO 0x2e
  861. #define PSYCHO_CE_INO 0x2f
  862. #define PSYCHO_PCIERR_A_INO 0x30
  863. #define PSYCHO_PCIERR_B_INO 0x31
  864. static void psycho_register_error_handlers(struct pci_controller_info *p)
  865. {
  866. struct pci_pbm_info *pbm = &p->pbm_A; /* arbitrary */
  867. unsigned long base = p->pbm_A.controller_regs;
  868. unsigned int irq, portid = pbm->portid;
  869. u64 tmp;
  870. /* Build IRQs and register handlers. */
  871. irq = psycho_irq_build(pbm, NULL, (portid << 6) | PSYCHO_UE_INO);
  872. if (request_irq(irq, psycho_ue_intr,
  873. SA_SHIRQ, "PSYCHO UE", p) < 0) {
  874. prom_printf("PSYCHO%d: Cannot register UE interrupt.\n",
  875. p->index);
  876. prom_halt();
  877. }
  878. irq = psycho_irq_build(pbm, NULL, (portid << 6) | PSYCHO_CE_INO);
  879. if (request_irq(irq, psycho_ce_intr,
  880. SA_SHIRQ, "PSYCHO CE", p) < 0) {
  881. prom_printf("PSYCHO%d: Cannot register CE interrupt.\n",
  882. p->index);
  883. prom_halt();
  884. }
  885. pbm = &p->pbm_A;
  886. irq = psycho_irq_build(pbm, NULL, (portid << 6) | PSYCHO_PCIERR_A_INO);
  887. if (request_irq(irq, psycho_pcierr_intr,
  888. SA_SHIRQ, "PSYCHO PCIERR", &p->pbm_A) < 0) {
  889. prom_printf("PSYCHO%d(PBMA): Cannot register PciERR interrupt.\n",
  890. p->index);
  891. prom_halt();
  892. }
  893. pbm = &p->pbm_B;
  894. irq = psycho_irq_build(pbm, NULL, (portid << 6) | PSYCHO_PCIERR_B_INO);
  895. if (request_irq(irq, psycho_pcierr_intr,
  896. SA_SHIRQ, "PSYCHO PCIERR", &p->pbm_B) < 0) {
  897. prom_printf("PSYCHO%d(PBMB): Cannot register PciERR interrupt.\n",
  898. p->index);
  899. prom_halt();
  900. }
  901. /* Enable UE and CE interrupts for controller. */
  902. psycho_write(base + PSYCHO_ECC_CTRL,
  903. (PSYCHO_ECCCTRL_EE |
  904. PSYCHO_ECCCTRL_UE |
  905. PSYCHO_ECCCTRL_CE));
  906. /* Enable PCI Error interrupts and clear error
  907. * bits for each PBM.
  908. */
  909. tmp = psycho_read(base + PSYCHO_PCIA_CTRL);
  910. tmp |= (PSYCHO_PCICTRL_SERR |
  911. PSYCHO_PCICTRL_SBH_ERR |
  912. PSYCHO_PCICTRL_EEN);
  913. tmp &= ~(PSYCHO_PCICTRL_SBH_INT);
  914. psycho_write(base + PSYCHO_PCIA_CTRL, tmp);
  915. tmp = psycho_read(base + PSYCHO_PCIB_CTRL);
  916. tmp |= (PSYCHO_PCICTRL_SERR |
  917. PSYCHO_PCICTRL_SBH_ERR |
  918. PSYCHO_PCICTRL_EEN);
  919. tmp &= ~(PSYCHO_PCICTRL_SBH_INT);
  920. psycho_write(base + PSYCHO_PCIB_CTRL, tmp);
  921. }
  922. /* PSYCHO boot time probing and initialization. */
  923. static void psycho_resource_adjust(struct pci_dev *pdev,
  924. struct resource *res,
  925. struct resource *root)
  926. {
  927. res->start += root->start;
  928. res->end += root->start;
  929. }
  930. static void psycho_base_address_update(struct pci_dev *pdev, int resource)
  931. {
  932. struct pcidev_cookie *pcp = pdev->sysdata;
  933. struct pci_pbm_info *pbm = pcp->pbm;
  934. struct resource *res, *root;
  935. u32 reg;
  936. int where, size, is_64bit;
  937. res = &pdev->resource[resource];
  938. if (resource < 6) {
  939. where = PCI_BASE_ADDRESS_0 + (resource * 4);
  940. } else if (resource == PCI_ROM_RESOURCE) {
  941. where = pdev->rom_base_reg;
  942. } else {
  943. /* Somebody might have asked allocation of a non-standard resource */
  944. return;
  945. }
  946. is_64bit = 0;
  947. if (res->flags & IORESOURCE_IO)
  948. root = &pbm->io_space;
  949. else {
  950. root = &pbm->mem_space;
  951. if ((res->flags & PCI_BASE_ADDRESS_MEM_TYPE_MASK)
  952. == PCI_BASE_ADDRESS_MEM_TYPE_64)
  953. is_64bit = 1;
  954. }
  955. size = res->end - res->start;
  956. pci_read_config_dword(pdev, where, &reg);
  957. reg = ((reg & size) |
  958. (((u32)(res->start - root->start)) & ~size));
  959. if (resource == PCI_ROM_RESOURCE) {
  960. reg |= PCI_ROM_ADDRESS_ENABLE;
  961. res->flags |= IORESOURCE_ROM_ENABLE;
  962. }
  963. pci_write_config_dword(pdev, where, reg);
  964. /* This knows that the upper 32-bits of the address
  965. * must be zero. Our PCI common layer enforces this.
  966. */
  967. if (is_64bit)
  968. pci_write_config_dword(pdev, where + 4, 0);
  969. }
  970. static void pbm_config_busmastering(struct pci_pbm_info *pbm)
  971. {
  972. u8 *addr;
  973. /* Set cache-line size to 64 bytes, this is actually
  974. * a nop but I do it for completeness.
  975. */
  976. addr = psycho_pci_config_mkaddr(pbm, pbm->pci_first_busno,
  977. 0, PCI_CACHE_LINE_SIZE);
  978. pci_config_write8(addr, 64 / sizeof(u32));
  979. /* Set PBM latency timer to 64 PCI clocks. */
  980. addr = psycho_pci_config_mkaddr(pbm, pbm->pci_first_busno,
  981. 0, PCI_LATENCY_TIMER);
  982. pci_config_write8(addr, 64);
  983. }
  984. static void pbm_scan_bus(struct pci_controller_info *p,
  985. struct pci_pbm_info *pbm)
  986. {
  987. struct pcidev_cookie *cookie = kzalloc(sizeof(*cookie), GFP_KERNEL);
  988. if (!cookie) {
  989. prom_printf("PSYCHO: Critical allocation failure.\n");
  990. prom_halt();
  991. }
  992. /* All we care about is the PBM. */
  993. cookie->pbm = pbm;
  994. pbm->pci_bus = pci_scan_bus(pbm->pci_first_busno,
  995. p->pci_ops,
  996. pbm);
  997. pci_fixup_host_bridge_self(pbm->pci_bus);
  998. pbm->pci_bus->self->sysdata = cookie;
  999. pci_fill_in_pbm_cookies(pbm->pci_bus, pbm, pbm->prom_node);
  1000. pci_record_assignments(pbm, pbm->pci_bus);
  1001. pci_assign_unassigned(pbm, pbm->pci_bus);
  1002. pci_fixup_irq(pbm, pbm->pci_bus);
  1003. pci_determine_66mhz_disposition(pbm, pbm->pci_bus);
  1004. pci_setup_busmastering(pbm, pbm->pci_bus);
  1005. }
  1006. static void psycho_scan_bus(struct pci_controller_info *p)
  1007. {
  1008. pbm_config_busmastering(&p->pbm_B);
  1009. p->pbm_B.is_66mhz_capable = 0;
  1010. pbm_config_busmastering(&p->pbm_A);
  1011. p->pbm_A.is_66mhz_capable = 1;
  1012. pbm_scan_bus(p, &p->pbm_B);
  1013. pbm_scan_bus(p, &p->pbm_A);
  1014. /* After the PCI bus scan is complete, we can register
  1015. * the error interrupt handlers.
  1016. */
  1017. psycho_register_error_handlers(p);
  1018. }
  1019. static void psycho_iommu_init(struct pci_controller_info *p)
  1020. {
  1021. struct pci_iommu *iommu = p->pbm_A.iommu;
  1022. unsigned long i;
  1023. u64 control;
  1024. /* Register addresses. */
  1025. iommu->iommu_control = p->pbm_A.controller_regs + PSYCHO_IOMMU_CONTROL;
  1026. iommu->iommu_tsbbase = p->pbm_A.controller_regs + PSYCHO_IOMMU_TSBBASE;
  1027. iommu->iommu_flush = p->pbm_A.controller_regs + PSYCHO_IOMMU_FLUSH;
  1028. /* PSYCHO's IOMMU lacks ctx flushing. */
  1029. iommu->iommu_ctxflush = 0;
  1030. /* We use the main control register of PSYCHO as the write
  1031. * completion register.
  1032. */
  1033. iommu->write_complete_reg = p->pbm_A.controller_regs + PSYCHO_CONTROL;
  1034. /*
  1035. * Invalidate TLB Entries.
  1036. */
  1037. control = psycho_read(p->pbm_A.controller_regs + PSYCHO_IOMMU_CONTROL);
  1038. control |= PSYCHO_IOMMU_CTRL_DENAB;
  1039. psycho_write(p->pbm_A.controller_regs + PSYCHO_IOMMU_CONTROL, control);
  1040. for(i = 0; i < 16; i++) {
  1041. psycho_write(p->pbm_A.controller_regs + PSYCHO_IOMMU_TAG + (i * 8UL), 0);
  1042. psycho_write(p->pbm_A.controller_regs + PSYCHO_IOMMU_DATA + (i * 8UL), 0);
  1043. }
  1044. /* Leave diag mode enabled for full-flushing done
  1045. * in pci_iommu.c
  1046. */
  1047. pci_iommu_table_init(iommu, IO_TSB_SIZE, 0xc0000000, 0xffffffff);
  1048. psycho_write(p->pbm_A.controller_regs + PSYCHO_IOMMU_TSBBASE,
  1049. __pa(iommu->page_table));
  1050. control = psycho_read(p->pbm_A.controller_regs + PSYCHO_IOMMU_CONTROL);
  1051. control &= ~(PSYCHO_IOMMU_CTRL_TSBSZ | PSYCHO_IOMMU_CTRL_TBWSZ);
  1052. control |= (PSYCHO_IOMMU_TSBSZ_128K | PSYCHO_IOMMU_CTRL_ENAB);
  1053. psycho_write(p->pbm_A.controller_regs + PSYCHO_IOMMU_CONTROL, control);
  1054. /* If necessary, hook us up for starfire IRQ translations. */
  1055. if (this_is_starfire)
  1056. p->starfire_cookie = starfire_hookup(p->pbm_A.portid);
  1057. else
  1058. p->starfire_cookie = NULL;
  1059. }
  1060. #define PSYCHO_IRQ_RETRY 0x1a00UL
  1061. #define PSYCHO_PCIA_DIAG 0x2020UL
  1062. #define PSYCHO_PCIB_DIAG 0x4020UL
  1063. #define PSYCHO_PCIDIAG_RESV 0xffffffffffffff80UL /* Reserved */
  1064. #define PSYCHO_PCIDIAG_DRETRY 0x0000000000000040UL /* Disable retry limit */
  1065. #define PSYCHO_PCIDIAG_DISYNC 0x0000000000000020UL /* Disable DMA wr / irq sync */
  1066. #define PSYCHO_PCIDIAG_DDWSYNC 0x0000000000000010UL /* Disable DMA wr / PIO rd sync */
  1067. #define PSYCHO_PCIDIAG_IDDPAR 0x0000000000000008UL /* Invert DMA data parity */
  1068. #define PSYCHO_PCIDIAG_IPDPAR 0x0000000000000004UL /* Invert PIO data parity */
  1069. #define PSYCHO_PCIDIAG_IPAPAR 0x0000000000000002UL /* Invert PIO address parity */
  1070. #define PSYCHO_PCIDIAG_LPBACK 0x0000000000000001UL /* Enable loopback mode */
  1071. static void psycho_controller_hwinit(struct pci_controller_info *p)
  1072. {
  1073. u64 tmp;
  1074. psycho_write(p->pbm_A.controller_regs + PSYCHO_IRQ_RETRY, 5);
  1075. /* Enable arbiter for all PCI slots. */
  1076. tmp = psycho_read(p->pbm_A.controller_regs + PSYCHO_PCIA_CTRL);
  1077. tmp |= PSYCHO_PCICTRL_AEN;
  1078. psycho_write(p->pbm_A.controller_regs + PSYCHO_PCIA_CTRL, tmp);
  1079. tmp = psycho_read(p->pbm_A.controller_regs + PSYCHO_PCIB_CTRL);
  1080. tmp |= PSYCHO_PCICTRL_AEN;
  1081. psycho_write(p->pbm_A.controller_regs + PSYCHO_PCIB_CTRL, tmp);
  1082. /* Disable DMA write / PIO read synchronization on
  1083. * both PCI bus segments.
  1084. * [ U2P Erratum 1243770, STP2223BGA data sheet ]
  1085. */
  1086. tmp = psycho_read(p->pbm_A.controller_regs + PSYCHO_PCIA_DIAG);
  1087. tmp |= PSYCHO_PCIDIAG_DDWSYNC;
  1088. psycho_write(p->pbm_A.controller_regs + PSYCHO_PCIA_DIAG, tmp);
  1089. tmp = psycho_read(p->pbm_A.controller_regs + PSYCHO_PCIB_DIAG);
  1090. tmp |= PSYCHO_PCIDIAG_DDWSYNC;
  1091. psycho_write(p->pbm_A.controller_regs + PSYCHO_PCIB_DIAG, tmp);
  1092. }
  1093. static void pbm_register_toplevel_resources(struct pci_controller_info *p,
  1094. struct pci_pbm_info *pbm)
  1095. {
  1096. char *name = pbm->name;
  1097. sprintf(name, "PSYCHO%d PBM%c",
  1098. p->index,
  1099. (pbm == &p->pbm_A ? 'A' : 'B'));
  1100. pbm->io_space.name = pbm->mem_space.name = name;
  1101. request_resource(&ioport_resource, &pbm->io_space);
  1102. request_resource(&iomem_resource, &pbm->mem_space);
  1103. pci_register_legacy_regions(&pbm->io_space,
  1104. &pbm->mem_space);
  1105. }
  1106. static void psycho_pbm_strbuf_init(struct pci_controller_info *p,
  1107. struct pci_pbm_info *pbm,
  1108. int is_pbm_a)
  1109. {
  1110. unsigned long base = pbm->controller_regs;
  1111. u64 control;
  1112. if (is_pbm_a) {
  1113. pbm->stc.strbuf_control = base + PSYCHO_STRBUF_CONTROL_A;
  1114. pbm->stc.strbuf_pflush = base + PSYCHO_STRBUF_FLUSH_A;
  1115. pbm->stc.strbuf_fsync = base + PSYCHO_STRBUF_FSYNC_A;
  1116. } else {
  1117. pbm->stc.strbuf_control = base + PSYCHO_STRBUF_CONTROL_B;
  1118. pbm->stc.strbuf_pflush = base + PSYCHO_STRBUF_FLUSH_B;
  1119. pbm->stc.strbuf_fsync = base + PSYCHO_STRBUF_FSYNC_B;
  1120. }
  1121. /* PSYCHO's streaming buffer lacks ctx flushing. */
  1122. pbm->stc.strbuf_ctxflush = 0;
  1123. pbm->stc.strbuf_ctxmatch_base = 0;
  1124. pbm->stc.strbuf_flushflag = (volatile unsigned long *)
  1125. ((((unsigned long)&pbm->stc.__flushflag_buf[0])
  1126. + 63UL)
  1127. & ~63UL);
  1128. pbm->stc.strbuf_flushflag_pa = (unsigned long)
  1129. __pa(pbm->stc.strbuf_flushflag);
  1130. /* Enable the streaming buffer. We have to be careful
  1131. * just in case OBP left it with LRU locking enabled.
  1132. *
  1133. * It is possible to control if PBM will be rerun on
  1134. * line misses. Currently I just retain whatever setting
  1135. * OBP left us with. All checks so far show it having
  1136. * a value of zero.
  1137. */
  1138. #undef PSYCHO_STRBUF_RERUN_ENABLE
  1139. #undef PSYCHO_STRBUF_RERUN_DISABLE
  1140. control = psycho_read(pbm->stc.strbuf_control);
  1141. control |= PSYCHO_STRBUF_CTRL_ENAB;
  1142. control &= ~(PSYCHO_STRBUF_CTRL_LENAB | PSYCHO_STRBUF_CTRL_LPTR);
  1143. #ifdef PSYCHO_STRBUF_RERUN_ENABLE
  1144. control &= ~(PSYCHO_STRBUF_CTRL_RRDIS);
  1145. #else
  1146. #ifdef PSYCHO_STRBUF_RERUN_DISABLE
  1147. control |= PSYCHO_STRBUF_CTRL_RRDIS;
  1148. #endif
  1149. #endif
  1150. psycho_write(pbm->stc.strbuf_control, control);
  1151. pbm->stc.strbuf_enabled = 1;
  1152. }
  1153. #define PSYCHO_IOSPACE_A 0x002000000UL
  1154. #define PSYCHO_IOSPACE_B 0x002010000UL
  1155. #define PSYCHO_IOSPACE_SIZE 0x00000ffffUL
  1156. #define PSYCHO_MEMSPACE_A 0x100000000UL
  1157. #define PSYCHO_MEMSPACE_B 0x180000000UL
  1158. #define PSYCHO_MEMSPACE_SIZE 0x07fffffffUL
  1159. static void psycho_pbm_init(struct pci_controller_info *p,
  1160. int prom_node, int is_pbm_a)
  1161. {
  1162. unsigned int busrange[2];
  1163. struct pci_pbm_info *pbm;
  1164. int err;
  1165. if (is_pbm_a) {
  1166. pbm = &p->pbm_A;
  1167. pbm->pci_first_slot = 1;
  1168. pbm->io_space.start = pbm->controller_regs + PSYCHO_IOSPACE_A;
  1169. pbm->mem_space.start = pbm->controller_regs + PSYCHO_MEMSPACE_A;
  1170. } else {
  1171. pbm = &p->pbm_B;
  1172. pbm->pci_first_slot = 2;
  1173. pbm->io_space.start = pbm->controller_regs + PSYCHO_IOSPACE_B;
  1174. pbm->mem_space.start = pbm->controller_regs + PSYCHO_MEMSPACE_B;
  1175. }
  1176. pbm->chip_type = PBM_CHIP_TYPE_PSYCHO;
  1177. pbm->chip_version =
  1178. prom_getintdefault(prom_node, "version#", 0);
  1179. pbm->chip_revision =
  1180. prom_getintdefault(prom_node, "module-revision#", 0);
  1181. pbm->io_space.end = pbm->io_space.start + PSYCHO_IOSPACE_SIZE;
  1182. pbm->io_space.flags = IORESOURCE_IO;
  1183. pbm->mem_space.end = pbm->mem_space.start + PSYCHO_MEMSPACE_SIZE;
  1184. pbm->mem_space.flags = IORESOURCE_MEM;
  1185. pbm_register_toplevel_resources(p, pbm);
  1186. pbm->parent = p;
  1187. pbm->prom_node = prom_node;
  1188. prom_getstring(prom_node, "name",
  1189. pbm->prom_name,
  1190. sizeof(pbm->prom_name));
  1191. err = prom_getproperty(prom_node, "ranges",
  1192. (char *)pbm->pbm_ranges,
  1193. sizeof(pbm->pbm_ranges));
  1194. if (err != -1)
  1195. pbm->num_pbm_ranges =
  1196. (err / sizeof(struct linux_prom_pci_ranges));
  1197. else
  1198. pbm->num_pbm_ranges = 0;
  1199. err = prom_getproperty(prom_node, "interrupt-map",
  1200. (char *)pbm->pbm_intmap,
  1201. sizeof(pbm->pbm_intmap));
  1202. if (err != -1) {
  1203. pbm->num_pbm_intmap = (err / sizeof(struct linux_prom_pci_intmap));
  1204. err = prom_getproperty(prom_node, "interrupt-map-mask",
  1205. (char *)&pbm->pbm_intmask,
  1206. sizeof(pbm->pbm_intmask));
  1207. if (err == -1) {
  1208. prom_printf("PSYCHO-PBM: Fatal error, no "
  1209. "interrupt-map-mask.\n");
  1210. prom_halt();
  1211. }
  1212. } else {
  1213. pbm->num_pbm_intmap = 0;
  1214. memset(&pbm->pbm_intmask, 0, sizeof(pbm->pbm_intmask));
  1215. }
  1216. err = prom_getproperty(prom_node, "bus-range",
  1217. (char *)&busrange[0],
  1218. sizeof(busrange));
  1219. if (err == 0 || err == -1) {
  1220. prom_printf("PSYCHO-PBM: Fatal error, no bus-range.\n");
  1221. prom_halt();
  1222. }
  1223. pbm->pci_first_busno = busrange[0];
  1224. pbm->pci_last_busno = busrange[1];
  1225. psycho_pbm_strbuf_init(p, pbm, is_pbm_a);
  1226. }
  1227. #define PSYCHO_CONFIGSPACE 0x001000000UL
  1228. void psycho_init(int node, char *model_name)
  1229. {
  1230. struct linux_prom64_registers pr_regs[3];
  1231. struct pci_controller_info *p;
  1232. struct pci_iommu *iommu;
  1233. u32 upa_portid;
  1234. int is_pbm_a, err;
  1235. upa_portid = prom_getintdefault(node, "upa-portid", 0xff);
  1236. for(p = pci_controller_root; p; p = p->next) {
  1237. if (p->pbm_A.portid == upa_portid) {
  1238. is_pbm_a = (p->pbm_A.prom_node == 0);
  1239. psycho_pbm_init(p, node, is_pbm_a);
  1240. return;
  1241. }
  1242. }
  1243. p = kzalloc(sizeof(struct pci_controller_info), GFP_ATOMIC);
  1244. if (!p) {
  1245. prom_printf("PSYCHO: Fatal memory allocation error.\n");
  1246. prom_halt();
  1247. }
  1248. iommu = kzalloc(sizeof(struct pci_iommu), GFP_ATOMIC);
  1249. if (!iommu) {
  1250. prom_printf("PSYCHO: Fatal memory allocation error.\n");
  1251. prom_halt();
  1252. }
  1253. p->pbm_A.iommu = p->pbm_B.iommu = iommu;
  1254. p->next = pci_controller_root;
  1255. pci_controller_root = p;
  1256. p->pbm_A.portid = upa_portid;
  1257. p->pbm_B.portid = upa_portid;
  1258. p->index = pci_num_controllers++;
  1259. p->pbms_same_domain = 0;
  1260. p->scan_bus = psycho_scan_bus;
  1261. p->irq_build = psycho_irq_build;
  1262. p->base_address_update = psycho_base_address_update;
  1263. p->resource_adjust = psycho_resource_adjust;
  1264. p->pci_ops = &psycho_ops;
  1265. err = prom_getproperty(node, "reg",
  1266. (char *)&pr_regs[0],
  1267. sizeof(pr_regs));
  1268. if (err == 0 || err == -1) {
  1269. prom_printf("PSYCHO: Fatal error, no reg property.\n");
  1270. prom_halt();
  1271. }
  1272. p->pbm_A.controller_regs = pr_regs[2].phys_addr;
  1273. p->pbm_B.controller_regs = pr_regs[2].phys_addr;
  1274. printk("PCI: Found PSYCHO, control regs at %016lx\n",
  1275. p->pbm_A.controller_regs);
  1276. p->pbm_A.config_space = p->pbm_B.config_space =
  1277. (pr_regs[2].phys_addr + PSYCHO_CONFIGSPACE);
  1278. printk("PSYCHO: Shared PCI config space at %016lx\n",
  1279. p->pbm_A.config_space);
  1280. /*
  1281. * Psycho's PCI MEM space is mapped to a 2GB aligned area, so
  1282. * we need to adjust our MEM space mask.
  1283. */
  1284. pci_memspace_mask = 0x7fffffffUL;
  1285. psycho_controller_hwinit(p);
  1286. psycho_iommu_init(p);
  1287. is_pbm_a = ((pr_regs[0].phys_addr & 0x6000) == 0x2000);
  1288. psycho_pbm_init(p, node, is_pbm_a);
  1289. }