pci_psycho.c 47 KB

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