pci_psycho.c 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522
  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. /* PCI PSYCHO INO number to Sparc PIL level. */
  251. static unsigned char psycho_pil_table[] = {
  252. /*0x00*/0, 0, 0, 0, /* PCI A slot 0 Int A, B, C, D */
  253. /*0x04*/0, 0, 0, 0, /* PCI A slot 1 Int A, B, C, D */
  254. /*0x08*/0, 0, 0, 0, /* PCI A slot 2 Int A, B, C, D */
  255. /*0x0c*/0, 0, 0, 0, /* PCI A slot 3 Int A, B, C, D */
  256. /*0x10*/0, 0, 0, 0, /* PCI B slot 0 Int A, B, C, D */
  257. /*0x14*/0, 0, 0, 0, /* PCI B slot 1 Int A, B, C, D */
  258. /*0x18*/0, 0, 0, 0, /* PCI B slot 2 Int A, B, C, D */
  259. /*0x1c*/0, 0, 0, 0, /* PCI B slot 3 Int A, B, C, D */
  260. /*0x20*/5, /* SCSI */
  261. /*0x21*/5, /* Ethernet */
  262. /*0x22*/8, /* Parallel Port */
  263. /*0x23*/13, /* Audio Record */
  264. /*0x24*/14, /* Audio Playback */
  265. /*0x25*/15, /* PowerFail */
  266. /*0x26*/5, /* second SCSI */
  267. /*0x27*/11, /* Floppy */
  268. /*0x28*/5, /* Spare Hardware */
  269. /*0x29*/9, /* Keyboard */
  270. /*0x2a*/5, /* Mouse */
  271. /*0x2b*/12, /* Serial */
  272. /*0x2c*/10, /* Timer 0 */
  273. /*0x2d*/11, /* Timer 1 */
  274. /*0x2e*/15, /* Uncorrectable ECC */
  275. /*0x2f*/15, /* Correctable ECC */
  276. /*0x30*/15, /* PCI Bus A Error */
  277. /*0x31*/15, /* PCI Bus B Error */
  278. /*0x32*/15, /* Power Management */
  279. };
  280. static int psycho_ino_to_pil(struct pci_dev *pdev, unsigned int ino)
  281. {
  282. int ret;
  283. ret = psycho_pil_table[ino];
  284. if (ret == 0 && pdev == NULL) {
  285. ret = 5;
  286. } else if (ret == 0) {
  287. switch ((pdev->class >> 16) & 0xff) {
  288. case PCI_BASE_CLASS_STORAGE:
  289. ret = 5;
  290. break;
  291. case PCI_BASE_CLASS_NETWORK:
  292. ret = 6;
  293. break;
  294. case PCI_BASE_CLASS_DISPLAY:
  295. ret = 9;
  296. break;
  297. case PCI_BASE_CLASS_MULTIMEDIA:
  298. case PCI_BASE_CLASS_MEMORY:
  299. case PCI_BASE_CLASS_BRIDGE:
  300. case PCI_BASE_CLASS_SERIAL:
  301. ret = 10;
  302. break;
  303. default:
  304. ret = 5;
  305. break;
  306. };
  307. }
  308. return ret;
  309. }
  310. static unsigned int psycho_irq_build(struct pci_pbm_info *pbm,
  311. struct pci_dev *pdev,
  312. unsigned int ino)
  313. {
  314. struct ino_bucket *bucket;
  315. unsigned long imap, iclr;
  316. unsigned long imap_off, iclr_off;
  317. int pil, inofixup = 0;
  318. ino &= PCI_IRQ_INO;
  319. if (ino < PSYCHO_ONBOARD_IRQ_BASE) {
  320. /* PCI slot */
  321. imap_off = psycho_pcislot_imap_offset(ino);
  322. } else {
  323. /* Onboard device */
  324. if (ino > PSYCHO_ONBOARD_IRQ_LAST) {
  325. prom_printf("psycho_irq_build: Wacky INO [%x]\n", ino);
  326. prom_halt();
  327. }
  328. imap_off = psycho_onboard_imap_offset(ino);
  329. }
  330. /* Now build the IRQ bucket. */
  331. pil = psycho_ino_to_pil(pdev, ino);
  332. if (PIL_RESERVED(pil))
  333. BUG();
  334. imap = pbm->controller_regs + imap_off;
  335. imap += 4;
  336. iclr_off = psycho_iclr_offset(ino);
  337. iclr = pbm->controller_regs + iclr_off;
  338. iclr += 4;
  339. if ((ino & 0x20) == 0)
  340. inofixup = ino & 0x03;
  341. bucket = __bucket(build_irq(pil, inofixup, iclr, imap));
  342. bucket->flags |= IBF_PCI;
  343. return __irq(bucket);
  344. }
  345. /* PSYCHO error handling support. */
  346. enum psycho_error_type {
  347. UE_ERR, CE_ERR, PCI_ERR
  348. };
  349. /* Helper function of IOMMU error checking, which checks out
  350. * the state of the streaming buffers. The IOMMU lock is
  351. * held when this is called.
  352. *
  353. * For the PCI error case we know which PBM (and thus which
  354. * streaming buffer) caused the error, but for the uncorrectable
  355. * error case we do not. So we always check both streaming caches.
  356. */
  357. #define PSYCHO_STRBUF_CONTROL_A 0x2800UL
  358. #define PSYCHO_STRBUF_CONTROL_B 0x4800UL
  359. #define PSYCHO_STRBUF_CTRL_LPTR 0x00000000000000f0UL /* LRU Lock Pointer */
  360. #define PSYCHO_STRBUF_CTRL_LENAB 0x0000000000000008UL /* LRU Lock Enable */
  361. #define PSYCHO_STRBUF_CTRL_RRDIS 0x0000000000000004UL /* Rerun Disable */
  362. #define PSYCHO_STRBUF_CTRL_DENAB 0x0000000000000002UL /* Diagnostic Mode Enable */
  363. #define PSYCHO_STRBUF_CTRL_ENAB 0x0000000000000001UL /* Streaming Buffer Enable */
  364. #define PSYCHO_STRBUF_FLUSH_A 0x2808UL
  365. #define PSYCHO_STRBUF_FLUSH_B 0x4808UL
  366. #define PSYCHO_STRBUF_FSYNC_A 0x2810UL
  367. #define PSYCHO_STRBUF_FSYNC_B 0x4810UL
  368. #define PSYCHO_STC_DATA_A 0xb000UL
  369. #define PSYCHO_STC_DATA_B 0xc000UL
  370. #define PSYCHO_STC_ERR_A 0xb400UL
  371. #define PSYCHO_STC_ERR_B 0xc400UL
  372. #define PSYCHO_STCERR_WRITE 0x0000000000000002UL /* Write Error */
  373. #define PSYCHO_STCERR_READ 0x0000000000000001UL /* Read Error */
  374. #define PSYCHO_STC_TAG_A 0xb800UL
  375. #define PSYCHO_STC_TAG_B 0xc800UL
  376. #define PSYCHO_STCTAG_PPN 0x0fffffff00000000UL /* Physical Page Number */
  377. #define PSYCHO_STCTAG_VPN 0x00000000ffffe000UL /* Virtual Page Number */
  378. #define PSYCHO_STCTAG_VALID 0x0000000000000002UL /* Valid */
  379. #define PSYCHO_STCTAG_WRITE 0x0000000000000001UL /* Writable */
  380. #define PSYCHO_STC_LINE_A 0xb900UL
  381. #define PSYCHO_STC_LINE_B 0xc900UL
  382. #define PSYCHO_STCLINE_LINDX 0x0000000001e00000UL /* LRU Index */
  383. #define PSYCHO_STCLINE_SPTR 0x00000000001f8000UL /* Dirty Data Start Pointer */
  384. #define PSYCHO_STCLINE_LADDR 0x0000000000007f00UL /* Line Address */
  385. #define PSYCHO_STCLINE_EPTR 0x00000000000000fcUL /* Dirty Data End Pointer */
  386. #define PSYCHO_STCLINE_VALID 0x0000000000000002UL /* Valid */
  387. #define PSYCHO_STCLINE_FOFN 0x0000000000000001UL /* Fetch Outstanding / Flush Necessary */
  388. static DEFINE_SPINLOCK(stc_buf_lock);
  389. static unsigned long stc_error_buf[128];
  390. static unsigned long stc_tag_buf[16];
  391. static unsigned long stc_line_buf[16];
  392. static void __psycho_check_one_stc(struct pci_controller_info *p,
  393. struct pci_pbm_info *pbm,
  394. int is_pbm_a)
  395. {
  396. struct pci_strbuf *strbuf = &pbm->stc;
  397. unsigned long regbase = p->pbm_A.controller_regs;
  398. unsigned long err_base, tag_base, line_base;
  399. u64 control;
  400. int i;
  401. if (is_pbm_a) {
  402. err_base = regbase + PSYCHO_STC_ERR_A;
  403. tag_base = regbase + PSYCHO_STC_TAG_A;
  404. line_base = regbase + PSYCHO_STC_LINE_A;
  405. } else {
  406. err_base = regbase + PSYCHO_STC_ERR_B;
  407. tag_base = regbase + PSYCHO_STC_TAG_B;
  408. line_base = regbase + PSYCHO_STC_LINE_B;
  409. }
  410. spin_lock(&stc_buf_lock);
  411. /* This is __REALLY__ dangerous. When we put the
  412. * streaming buffer into diagnostic mode to probe
  413. * it's tags and error status, we _must_ clear all
  414. * of the line tag valid bits before re-enabling
  415. * the streaming buffer. If any dirty data lives
  416. * in the STC when we do this, we will end up
  417. * invalidating it before it has a chance to reach
  418. * main memory.
  419. */
  420. control = psycho_read(strbuf->strbuf_control);
  421. psycho_write(strbuf->strbuf_control,
  422. (control | PSYCHO_STRBUF_CTRL_DENAB));
  423. for (i = 0; i < 128; i++) {
  424. unsigned long val;
  425. val = psycho_read(err_base + (i * 8UL));
  426. psycho_write(err_base + (i * 8UL), 0UL);
  427. stc_error_buf[i] = val;
  428. }
  429. for (i = 0; i < 16; i++) {
  430. stc_tag_buf[i] = psycho_read(tag_base + (i * 8UL));
  431. stc_line_buf[i] = psycho_read(line_base + (i * 8UL));
  432. psycho_write(tag_base + (i * 8UL), 0UL);
  433. psycho_write(line_base + (i * 8UL), 0UL);
  434. }
  435. /* OK, state is logged, exit diagnostic mode. */
  436. psycho_write(strbuf->strbuf_control, control);
  437. for (i = 0; i < 16; i++) {
  438. int j, saw_error, first, last;
  439. saw_error = 0;
  440. first = i * 8;
  441. last = first + 8;
  442. for (j = first; j < last; j++) {
  443. unsigned long errval = stc_error_buf[j];
  444. if (errval != 0) {
  445. saw_error++;
  446. printk("PSYCHO%d(PBM%c): STC_ERR(%d)[wr(%d)rd(%d)]\n",
  447. p->index,
  448. (is_pbm_a ? 'A' : 'B'),
  449. j,
  450. (errval & PSYCHO_STCERR_WRITE) ? 1 : 0,
  451. (errval & PSYCHO_STCERR_READ) ? 1 : 0);
  452. }
  453. }
  454. if (saw_error != 0) {
  455. unsigned long tagval = stc_tag_buf[i];
  456. unsigned long lineval = stc_line_buf[i];
  457. printk("PSYCHO%d(PBM%c): STC_TAG(%d)[PA(%016lx)VA(%08lx)V(%d)W(%d)]\n",
  458. p->index,
  459. (is_pbm_a ? 'A' : 'B'),
  460. i,
  461. ((tagval & PSYCHO_STCTAG_PPN) >> 19UL),
  462. (tagval & PSYCHO_STCTAG_VPN),
  463. ((tagval & PSYCHO_STCTAG_VALID) ? 1 : 0),
  464. ((tagval & PSYCHO_STCTAG_WRITE) ? 1 : 0));
  465. printk("PSYCHO%d(PBM%c): STC_LINE(%d)[LIDX(%lx)SP(%lx)LADDR(%lx)EP(%lx)"
  466. "V(%d)FOFN(%d)]\n",
  467. p->index,
  468. (is_pbm_a ? 'A' : 'B'),
  469. i,
  470. ((lineval & PSYCHO_STCLINE_LINDX) >> 21UL),
  471. ((lineval & PSYCHO_STCLINE_SPTR) >> 15UL),
  472. ((lineval & PSYCHO_STCLINE_LADDR) >> 8UL),
  473. ((lineval & PSYCHO_STCLINE_EPTR) >> 2UL),
  474. ((lineval & PSYCHO_STCLINE_VALID) ? 1 : 0),
  475. ((lineval & PSYCHO_STCLINE_FOFN) ? 1 : 0));
  476. }
  477. }
  478. spin_unlock(&stc_buf_lock);
  479. }
  480. static void __psycho_check_stc_error(struct pci_controller_info *p,
  481. unsigned long afsr,
  482. unsigned long afar,
  483. enum psycho_error_type type)
  484. {
  485. struct pci_pbm_info *pbm;
  486. pbm = &p->pbm_A;
  487. if (pbm->stc.strbuf_enabled)
  488. __psycho_check_one_stc(p, pbm, 1);
  489. pbm = &p->pbm_B;
  490. if (pbm->stc.strbuf_enabled)
  491. __psycho_check_one_stc(p, pbm, 0);
  492. }
  493. /* When an Uncorrectable Error or a PCI Error happens, we
  494. * interrogate the IOMMU state to see if it is the cause.
  495. */
  496. #define PSYCHO_IOMMU_CONTROL 0x0200UL
  497. #define PSYCHO_IOMMU_CTRL_RESV 0xfffffffff9000000UL /* Reserved */
  498. #define PSYCHO_IOMMU_CTRL_XLTESTAT 0x0000000006000000UL /* Translation Error Status */
  499. #define PSYCHO_IOMMU_CTRL_XLTEERR 0x0000000001000000UL /* Translation Error encountered */
  500. #define PSYCHO_IOMMU_CTRL_LCKEN 0x0000000000800000UL /* Enable translation locking */
  501. #define PSYCHO_IOMMU_CTRL_LCKPTR 0x0000000000780000UL /* Translation lock pointer */
  502. #define PSYCHO_IOMMU_CTRL_TSBSZ 0x0000000000070000UL /* TSB Size */
  503. #define PSYCHO_IOMMU_TSBSZ_1K 0x0000000000000000UL /* TSB Table 1024 8-byte entries */
  504. #define PSYCHO_IOMMU_TSBSZ_2K 0x0000000000010000UL /* TSB Table 2048 8-byte entries */
  505. #define PSYCHO_IOMMU_TSBSZ_4K 0x0000000000020000UL /* TSB Table 4096 8-byte entries */
  506. #define PSYCHO_IOMMU_TSBSZ_8K 0x0000000000030000UL /* TSB Table 8192 8-byte entries */
  507. #define PSYCHO_IOMMU_TSBSZ_16K 0x0000000000040000UL /* TSB Table 16k 8-byte entries */
  508. #define PSYCHO_IOMMU_TSBSZ_32K 0x0000000000050000UL /* TSB Table 32k 8-byte entries */
  509. #define PSYCHO_IOMMU_TSBSZ_64K 0x0000000000060000UL /* TSB Table 64k 8-byte entries */
  510. #define PSYCHO_IOMMU_TSBSZ_128K 0x0000000000070000UL /* TSB Table 128k 8-byte entries */
  511. #define PSYCHO_IOMMU_CTRL_RESV2 0x000000000000fff8UL /* Reserved */
  512. #define PSYCHO_IOMMU_CTRL_TBWSZ 0x0000000000000004UL /* Assumed page size, 0=8k 1=64k */
  513. #define PSYCHO_IOMMU_CTRL_DENAB 0x0000000000000002UL /* Diagnostic mode enable */
  514. #define PSYCHO_IOMMU_CTRL_ENAB 0x0000000000000001UL /* IOMMU Enable */
  515. #define PSYCHO_IOMMU_TSBBASE 0x0208UL
  516. #define PSYCHO_IOMMU_FLUSH 0x0210UL
  517. #define PSYCHO_IOMMU_TAG 0xa580UL
  518. #define PSYCHO_IOMMU_TAG_ERRSTS (0x3UL << 23UL)
  519. #define PSYCHO_IOMMU_TAG_ERR (0x1UL << 22UL)
  520. #define PSYCHO_IOMMU_TAG_WRITE (0x1UL << 21UL)
  521. #define PSYCHO_IOMMU_TAG_STREAM (0x1UL << 20UL)
  522. #define PSYCHO_IOMMU_TAG_SIZE (0x1UL << 19UL)
  523. #define PSYCHO_IOMMU_TAG_VPAGE 0x7ffffUL
  524. #define PSYCHO_IOMMU_DATA 0xa600UL
  525. #define PSYCHO_IOMMU_DATA_VALID (1UL << 30UL)
  526. #define PSYCHO_IOMMU_DATA_CACHE (1UL << 28UL)
  527. #define PSYCHO_IOMMU_DATA_PPAGE 0xfffffffUL
  528. static void psycho_check_iommu_error(struct pci_controller_info *p,
  529. unsigned long afsr,
  530. unsigned long afar,
  531. enum psycho_error_type type)
  532. {
  533. struct pci_iommu *iommu = p->pbm_A.iommu;
  534. unsigned long iommu_tag[16];
  535. unsigned long iommu_data[16];
  536. unsigned long flags;
  537. u64 control;
  538. int i;
  539. spin_lock_irqsave(&iommu->lock, flags);
  540. control = psycho_read(iommu->iommu_control);
  541. if (control & PSYCHO_IOMMU_CTRL_XLTEERR) {
  542. char *type_string;
  543. /* Clear the error encountered bit. */
  544. control &= ~PSYCHO_IOMMU_CTRL_XLTEERR;
  545. psycho_write(iommu->iommu_control, control);
  546. switch((control & PSYCHO_IOMMU_CTRL_XLTESTAT) >> 25UL) {
  547. case 0:
  548. type_string = "Protection Error";
  549. break;
  550. case 1:
  551. type_string = "Invalid Error";
  552. break;
  553. case 2:
  554. type_string = "TimeOut Error";
  555. break;
  556. case 3:
  557. default:
  558. type_string = "ECC Error";
  559. break;
  560. };
  561. printk("PSYCHO%d: IOMMU Error, type[%s]\n",
  562. p->index, type_string);
  563. /* Put the IOMMU into diagnostic mode and probe
  564. * it's TLB for entries with error status.
  565. *
  566. * It is very possible for another DVMA to occur
  567. * while we do this probe, and corrupt the system
  568. * further. But we are so screwed at this point
  569. * that we are likely to crash hard anyways, so
  570. * get as much diagnostic information to the
  571. * console as we can.
  572. */
  573. psycho_write(iommu->iommu_control,
  574. control | PSYCHO_IOMMU_CTRL_DENAB);
  575. for (i = 0; i < 16; i++) {
  576. unsigned long base = p->pbm_A.controller_regs;
  577. iommu_tag[i] =
  578. psycho_read(base + PSYCHO_IOMMU_TAG + (i * 8UL));
  579. iommu_data[i] =
  580. psycho_read(base + PSYCHO_IOMMU_DATA + (i * 8UL));
  581. /* Now clear out the entry. */
  582. psycho_write(base + PSYCHO_IOMMU_TAG + (i * 8UL), 0);
  583. psycho_write(base + PSYCHO_IOMMU_DATA + (i * 8UL), 0);
  584. }
  585. /* Leave diagnostic mode. */
  586. psycho_write(iommu->iommu_control, control);
  587. for (i = 0; i < 16; i++) {
  588. unsigned long tag, data;
  589. tag = iommu_tag[i];
  590. if (!(tag & PSYCHO_IOMMU_TAG_ERR))
  591. continue;
  592. data = iommu_data[i];
  593. switch((tag & PSYCHO_IOMMU_TAG_ERRSTS) >> 23UL) {
  594. case 0:
  595. type_string = "Protection Error";
  596. break;
  597. case 1:
  598. type_string = "Invalid Error";
  599. break;
  600. case 2:
  601. type_string = "TimeOut Error";
  602. break;
  603. case 3:
  604. default:
  605. type_string = "ECC Error";
  606. break;
  607. };
  608. printk("PSYCHO%d: IOMMU TAG(%d)[error(%s) wr(%d) str(%d) sz(%dK) vpg(%08lx)]\n",
  609. p->index, i, type_string,
  610. ((tag & PSYCHO_IOMMU_TAG_WRITE) ? 1 : 0),
  611. ((tag & PSYCHO_IOMMU_TAG_STREAM) ? 1 : 0),
  612. ((tag & PSYCHO_IOMMU_TAG_SIZE) ? 64 : 8),
  613. (tag & PSYCHO_IOMMU_TAG_VPAGE) << IOMMU_PAGE_SHIFT);
  614. printk("PSYCHO%d: IOMMU DATA(%d)[valid(%d) cache(%d) ppg(%016lx)]\n",
  615. p->index, i,
  616. ((data & PSYCHO_IOMMU_DATA_VALID) ? 1 : 0),
  617. ((data & PSYCHO_IOMMU_DATA_CACHE) ? 1 : 0),
  618. (data & PSYCHO_IOMMU_DATA_PPAGE) << IOMMU_PAGE_SHIFT);
  619. }
  620. }
  621. __psycho_check_stc_error(p, afsr, afar, type);
  622. spin_unlock_irqrestore(&iommu->lock, flags);
  623. }
  624. /* Uncorrectable Errors. Cause of the error and the address are
  625. * recorded in the UE_AFSR and UE_AFAR of PSYCHO. They are errors
  626. * relating to UPA interface transactions.
  627. */
  628. #define PSYCHO_UE_AFSR 0x0030UL
  629. #define PSYCHO_UEAFSR_PPIO 0x8000000000000000UL /* Primary PIO is cause */
  630. #define PSYCHO_UEAFSR_PDRD 0x4000000000000000UL /* Primary DVMA read is cause */
  631. #define PSYCHO_UEAFSR_PDWR 0x2000000000000000UL /* Primary DVMA write is cause */
  632. #define PSYCHO_UEAFSR_SPIO 0x1000000000000000UL /* Secondary PIO is cause */
  633. #define PSYCHO_UEAFSR_SDRD 0x0800000000000000UL /* Secondary DVMA read is cause */
  634. #define PSYCHO_UEAFSR_SDWR 0x0400000000000000UL /* Secondary DVMA write is cause*/
  635. #define PSYCHO_UEAFSR_RESV1 0x03ff000000000000UL /* Reserved */
  636. #define PSYCHO_UEAFSR_BMSK 0x0000ffff00000000UL /* Bytemask of failed transfer */
  637. #define PSYCHO_UEAFSR_DOFF 0x00000000e0000000UL /* Doubleword Offset */
  638. #define PSYCHO_UEAFSR_MID 0x000000001f000000UL /* UPA MID causing the fault */
  639. #define PSYCHO_UEAFSR_BLK 0x0000000000800000UL /* Trans was block operation */
  640. #define PSYCHO_UEAFSR_RESV2 0x00000000007fffffUL /* Reserved */
  641. #define PSYCHO_UE_AFAR 0x0038UL
  642. static irqreturn_t psycho_ue_intr(int irq, void *dev_id, struct pt_regs *regs)
  643. {
  644. struct pci_controller_info *p = dev_id;
  645. unsigned long afsr_reg = p->pbm_A.controller_regs + PSYCHO_UE_AFSR;
  646. unsigned long afar_reg = p->pbm_A.controller_regs + PSYCHO_UE_AFAR;
  647. unsigned long afsr, afar, error_bits;
  648. int reported;
  649. /* Latch uncorrectable error status. */
  650. afar = psycho_read(afar_reg);
  651. afsr = psycho_read(afsr_reg);
  652. /* Clear the primary/secondary error status bits. */
  653. error_bits = afsr &
  654. (PSYCHO_UEAFSR_PPIO | PSYCHO_UEAFSR_PDRD | PSYCHO_UEAFSR_PDWR |
  655. PSYCHO_UEAFSR_SPIO | PSYCHO_UEAFSR_SDRD | PSYCHO_UEAFSR_SDWR);
  656. if (!error_bits)
  657. return IRQ_NONE;
  658. psycho_write(afsr_reg, error_bits);
  659. /* Log the error. */
  660. printk("PSYCHO%d: Uncorrectable Error, primary error type[%s]\n",
  661. p->index,
  662. (((error_bits & PSYCHO_UEAFSR_PPIO) ?
  663. "PIO" :
  664. ((error_bits & PSYCHO_UEAFSR_PDRD) ?
  665. "DMA Read" :
  666. ((error_bits & PSYCHO_UEAFSR_PDWR) ?
  667. "DMA Write" : "???")))));
  668. printk("PSYCHO%d: bytemask[%04lx] dword_offset[%lx] UPA_MID[%02lx] was_block(%d)\n",
  669. p->index,
  670. (afsr & PSYCHO_UEAFSR_BMSK) >> 32UL,
  671. (afsr & PSYCHO_UEAFSR_DOFF) >> 29UL,
  672. (afsr & PSYCHO_UEAFSR_MID) >> 24UL,
  673. ((afsr & PSYCHO_UEAFSR_BLK) ? 1 : 0));
  674. printk("PSYCHO%d: UE AFAR [%016lx]\n", p->index, afar);
  675. printk("PSYCHO%d: UE Secondary errors [", p->index);
  676. reported = 0;
  677. if (afsr & PSYCHO_UEAFSR_SPIO) {
  678. reported++;
  679. printk("(PIO)");
  680. }
  681. if (afsr & PSYCHO_UEAFSR_SDRD) {
  682. reported++;
  683. printk("(DMA Read)");
  684. }
  685. if (afsr & PSYCHO_UEAFSR_SDWR) {
  686. reported++;
  687. printk("(DMA Write)");
  688. }
  689. if (!reported)
  690. printk("(none)");
  691. printk("]\n");
  692. /* Interrogate IOMMU for error status. */
  693. psycho_check_iommu_error(p, afsr, afar, UE_ERR);
  694. return IRQ_HANDLED;
  695. }
  696. /* Correctable Errors. */
  697. #define PSYCHO_CE_AFSR 0x0040UL
  698. #define PSYCHO_CEAFSR_PPIO 0x8000000000000000UL /* Primary PIO is cause */
  699. #define PSYCHO_CEAFSR_PDRD 0x4000000000000000UL /* Primary DVMA read is cause */
  700. #define PSYCHO_CEAFSR_PDWR 0x2000000000000000UL /* Primary DVMA write is cause */
  701. #define PSYCHO_CEAFSR_SPIO 0x1000000000000000UL /* Secondary PIO is cause */
  702. #define PSYCHO_CEAFSR_SDRD 0x0800000000000000UL /* Secondary DVMA read is cause */
  703. #define PSYCHO_CEAFSR_SDWR 0x0400000000000000UL /* Secondary DVMA write is cause*/
  704. #define PSYCHO_CEAFSR_RESV1 0x0300000000000000UL /* Reserved */
  705. #define PSYCHO_CEAFSR_ESYND 0x00ff000000000000UL /* Syndrome Bits */
  706. #define PSYCHO_CEAFSR_BMSK 0x0000ffff00000000UL /* Bytemask of failed transfer */
  707. #define PSYCHO_CEAFSR_DOFF 0x00000000e0000000UL /* Double Offset */
  708. #define PSYCHO_CEAFSR_MID 0x000000001f000000UL /* UPA MID causing the fault */
  709. #define PSYCHO_CEAFSR_BLK 0x0000000000800000UL /* Trans was block operation */
  710. #define PSYCHO_CEAFSR_RESV2 0x00000000007fffffUL /* Reserved */
  711. #define PSYCHO_CE_AFAR 0x0040UL
  712. static irqreturn_t psycho_ce_intr(int irq, void *dev_id, struct pt_regs *regs)
  713. {
  714. struct pci_controller_info *p = dev_id;
  715. unsigned long afsr_reg = p->pbm_A.controller_regs + PSYCHO_CE_AFSR;
  716. unsigned long afar_reg = p->pbm_A.controller_regs + PSYCHO_CE_AFAR;
  717. unsigned long afsr, afar, error_bits;
  718. int reported;
  719. /* Latch error status. */
  720. afar = psycho_read(afar_reg);
  721. afsr = psycho_read(afsr_reg);
  722. /* Clear primary/secondary error status bits. */
  723. error_bits = afsr &
  724. (PSYCHO_CEAFSR_PPIO | PSYCHO_CEAFSR_PDRD | PSYCHO_CEAFSR_PDWR |
  725. PSYCHO_CEAFSR_SPIO | PSYCHO_CEAFSR_SDRD | PSYCHO_CEAFSR_SDWR);
  726. if (!error_bits)
  727. return IRQ_NONE;
  728. psycho_write(afsr_reg, error_bits);
  729. /* Log the error. */
  730. printk("PSYCHO%d: Correctable Error, primary error type[%s]\n",
  731. p->index,
  732. (((error_bits & PSYCHO_CEAFSR_PPIO) ?
  733. "PIO" :
  734. ((error_bits & PSYCHO_CEAFSR_PDRD) ?
  735. "DMA Read" :
  736. ((error_bits & PSYCHO_CEAFSR_PDWR) ?
  737. "DMA Write" : "???")))));
  738. /* XXX Use syndrome and afar to print out module string just like
  739. * XXX UDB CE trap handler does... -DaveM
  740. */
  741. printk("PSYCHO%d: syndrome[%02lx] bytemask[%04lx] dword_offset[%lx] "
  742. "UPA_MID[%02lx] was_block(%d)\n",
  743. p->index,
  744. (afsr & PSYCHO_CEAFSR_ESYND) >> 48UL,
  745. (afsr & PSYCHO_CEAFSR_BMSK) >> 32UL,
  746. (afsr & PSYCHO_CEAFSR_DOFF) >> 29UL,
  747. (afsr & PSYCHO_CEAFSR_MID) >> 24UL,
  748. ((afsr & PSYCHO_CEAFSR_BLK) ? 1 : 0));
  749. printk("PSYCHO%d: CE AFAR [%016lx]\n", p->index, afar);
  750. printk("PSYCHO%d: CE Secondary errors [", p->index);
  751. reported = 0;
  752. if (afsr & PSYCHO_CEAFSR_SPIO) {
  753. reported++;
  754. printk("(PIO)");
  755. }
  756. if (afsr & PSYCHO_CEAFSR_SDRD) {
  757. reported++;
  758. printk("(DMA Read)");
  759. }
  760. if (afsr & PSYCHO_CEAFSR_SDWR) {
  761. reported++;
  762. printk("(DMA Write)");
  763. }
  764. if (!reported)
  765. printk("(none)");
  766. printk("]\n");
  767. return IRQ_HANDLED;
  768. }
  769. /* PCI Errors. They are signalled by the PCI bus module since they
  770. * are associated with a specific bus segment.
  771. */
  772. #define PSYCHO_PCI_AFSR_A 0x2010UL
  773. #define PSYCHO_PCI_AFSR_B 0x4010UL
  774. #define PSYCHO_PCIAFSR_PMA 0x8000000000000000UL /* Primary Master Abort Error */
  775. #define PSYCHO_PCIAFSR_PTA 0x4000000000000000UL /* Primary Target Abort Error */
  776. #define PSYCHO_PCIAFSR_PRTRY 0x2000000000000000UL /* Primary Excessive Retries */
  777. #define PSYCHO_PCIAFSR_PPERR 0x1000000000000000UL /* Primary Parity Error */
  778. #define PSYCHO_PCIAFSR_SMA 0x0800000000000000UL /* Secondary Master Abort Error */
  779. #define PSYCHO_PCIAFSR_STA 0x0400000000000000UL /* Secondary Target Abort Error */
  780. #define PSYCHO_PCIAFSR_SRTRY 0x0200000000000000UL /* Secondary Excessive Retries */
  781. #define PSYCHO_PCIAFSR_SPERR 0x0100000000000000UL /* Secondary Parity Error */
  782. #define PSYCHO_PCIAFSR_RESV1 0x00ff000000000000UL /* Reserved */
  783. #define PSYCHO_PCIAFSR_BMSK 0x0000ffff00000000UL /* Bytemask of failed transfer */
  784. #define PSYCHO_PCIAFSR_BLK 0x0000000080000000UL /* Trans was block operation */
  785. #define PSYCHO_PCIAFSR_RESV2 0x0000000040000000UL /* Reserved */
  786. #define PSYCHO_PCIAFSR_MID 0x000000003e000000UL /* MID causing the error */
  787. #define PSYCHO_PCIAFSR_RESV3 0x0000000001ffffffUL /* Reserved */
  788. #define PSYCHO_PCI_AFAR_A 0x2018UL
  789. #define PSYCHO_PCI_AFAR_B 0x4018UL
  790. static irqreturn_t psycho_pcierr_intr_other(struct pci_pbm_info *pbm, int is_pbm_a)
  791. {
  792. unsigned long csr_reg, csr, csr_error_bits;
  793. irqreturn_t ret = IRQ_NONE;
  794. u16 stat;
  795. if (is_pbm_a) {
  796. csr_reg = pbm->controller_regs + PSYCHO_PCIA_CTRL;
  797. } else {
  798. csr_reg = pbm->controller_regs + PSYCHO_PCIB_CTRL;
  799. }
  800. csr = psycho_read(csr_reg);
  801. csr_error_bits =
  802. csr & (PSYCHO_PCICTRL_SBH_ERR | PSYCHO_PCICTRL_SERR);
  803. if (csr_error_bits) {
  804. /* Clear the errors. */
  805. psycho_write(csr_reg, csr);
  806. /* Log 'em. */
  807. if (csr_error_bits & PSYCHO_PCICTRL_SBH_ERR)
  808. printk("%s: PCI streaming byte hole error asserted.\n",
  809. pbm->name);
  810. if (csr_error_bits & PSYCHO_PCICTRL_SERR)
  811. printk("%s: PCI SERR signal asserted.\n", pbm->name);
  812. ret = IRQ_HANDLED;
  813. }
  814. pci_read_config_word(pbm->pci_bus->self, PCI_STATUS, &stat);
  815. if (stat & (PCI_STATUS_PARITY |
  816. PCI_STATUS_SIG_TARGET_ABORT |
  817. PCI_STATUS_REC_TARGET_ABORT |
  818. PCI_STATUS_REC_MASTER_ABORT |
  819. PCI_STATUS_SIG_SYSTEM_ERROR)) {
  820. printk("%s: PCI bus error, PCI_STATUS[%04x]\n",
  821. pbm->name, stat);
  822. pci_write_config_word(pbm->pci_bus->self, PCI_STATUS, 0xffff);
  823. ret = IRQ_HANDLED;
  824. }
  825. return ret;
  826. }
  827. static irqreturn_t psycho_pcierr_intr(int irq, void *dev_id, struct pt_regs *regs)
  828. {
  829. struct pci_pbm_info *pbm = dev_id;
  830. struct pci_controller_info *p = pbm->parent;
  831. unsigned long afsr_reg, afar_reg;
  832. unsigned long afsr, afar, error_bits;
  833. int is_pbm_a, reported;
  834. is_pbm_a = (pbm == &pbm->parent->pbm_A);
  835. if (is_pbm_a) {
  836. afsr_reg = p->pbm_A.controller_regs + PSYCHO_PCI_AFSR_A;
  837. afar_reg = p->pbm_A.controller_regs + PSYCHO_PCI_AFAR_A;
  838. } else {
  839. afsr_reg = p->pbm_A.controller_regs + PSYCHO_PCI_AFSR_B;
  840. afar_reg = p->pbm_A.controller_regs + PSYCHO_PCI_AFAR_B;
  841. }
  842. /* Latch error status. */
  843. afar = psycho_read(afar_reg);
  844. afsr = psycho_read(afsr_reg);
  845. /* Clear primary/secondary error status bits. */
  846. error_bits = afsr &
  847. (PSYCHO_PCIAFSR_PMA | PSYCHO_PCIAFSR_PTA |
  848. PSYCHO_PCIAFSR_PRTRY | PSYCHO_PCIAFSR_PPERR |
  849. PSYCHO_PCIAFSR_SMA | PSYCHO_PCIAFSR_STA |
  850. PSYCHO_PCIAFSR_SRTRY | PSYCHO_PCIAFSR_SPERR);
  851. if (!error_bits)
  852. return psycho_pcierr_intr_other(pbm, is_pbm_a);
  853. psycho_write(afsr_reg, error_bits);
  854. /* Log the error. */
  855. printk("PSYCHO%d(PBM%c): PCI Error, primary error type[%s]\n",
  856. p->index, (is_pbm_a ? 'A' : 'B'),
  857. (((error_bits & PSYCHO_PCIAFSR_PMA) ?
  858. "Master Abort" :
  859. ((error_bits & PSYCHO_PCIAFSR_PTA) ?
  860. "Target Abort" :
  861. ((error_bits & PSYCHO_PCIAFSR_PRTRY) ?
  862. "Excessive Retries" :
  863. ((error_bits & PSYCHO_PCIAFSR_PPERR) ?
  864. "Parity Error" : "???"))))));
  865. printk("PSYCHO%d(PBM%c): bytemask[%04lx] UPA_MID[%02lx] was_block(%d)\n",
  866. p->index, (is_pbm_a ? 'A' : 'B'),
  867. (afsr & PSYCHO_PCIAFSR_BMSK) >> 32UL,
  868. (afsr & PSYCHO_PCIAFSR_MID) >> 25UL,
  869. (afsr & PSYCHO_PCIAFSR_BLK) ? 1 : 0);
  870. printk("PSYCHO%d(PBM%c): PCI AFAR [%016lx]\n",
  871. p->index, (is_pbm_a ? 'A' : 'B'), afar);
  872. printk("PSYCHO%d(PBM%c): PCI Secondary errors [",
  873. p->index, (is_pbm_a ? 'A' : 'B'));
  874. reported = 0;
  875. if (afsr & PSYCHO_PCIAFSR_SMA) {
  876. reported++;
  877. printk("(Master Abort)");
  878. }
  879. if (afsr & PSYCHO_PCIAFSR_STA) {
  880. reported++;
  881. printk("(Target Abort)");
  882. }
  883. if (afsr & PSYCHO_PCIAFSR_SRTRY) {
  884. reported++;
  885. printk("(Excessive Retries)");
  886. }
  887. if (afsr & PSYCHO_PCIAFSR_SPERR) {
  888. reported++;
  889. printk("(Parity Error)");
  890. }
  891. if (!reported)
  892. printk("(none)");
  893. printk("]\n");
  894. /* For the error types shown, scan PBM's PCI bus for devices
  895. * which have logged that error type.
  896. */
  897. /* If we see a Target Abort, this could be the result of an
  898. * IOMMU translation error of some sort. It is extremely
  899. * useful to log this information as usually it indicates
  900. * a bug in the IOMMU support code or a PCI device driver.
  901. */
  902. if (error_bits & (PSYCHO_PCIAFSR_PTA | PSYCHO_PCIAFSR_STA)) {
  903. psycho_check_iommu_error(p, afsr, afar, PCI_ERR);
  904. pci_scan_for_target_abort(p, pbm, pbm->pci_bus);
  905. }
  906. if (error_bits & (PSYCHO_PCIAFSR_PMA | PSYCHO_PCIAFSR_SMA))
  907. pci_scan_for_master_abort(p, pbm, pbm->pci_bus);
  908. /* For excessive retries, PSYCHO/PBM will abort the device
  909. * and there is no way to specifically check for excessive
  910. * retries in the config space status registers. So what
  911. * we hope is that we'll catch it via the master/target
  912. * abort events.
  913. */
  914. if (error_bits & (PSYCHO_PCIAFSR_PPERR | PSYCHO_PCIAFSR_SPERR))
  915. pci_scan_for_parity_error(p, pbm, pbm->pci_bus);
  916. return IRQ_HANDLED;
  917. }
  918. /* XXX What about PowerFail/PowerManagement??? -DaveM */
  919. #define PSYCHO_ECC_CTRL 0x0020
  920. #define PSYCHO_ECCCTRL_EE 0x8000000000000000UL /* Enable ECC Checking */
  921. #define PSYCHO_ECCCTRL_UE 0x4000000000000000UL /* Enable UE Interrupts */
  922. #define PSYCHO_ECCCTRL_CE 0x2000000000000000UL /* Enable CE INterrupts */
  923. #define PSYCHO_UE_INO 0x2e
  924. #define PSYCHO_CE_INO 0x2f
  925. #define PSYCHO_PCIERR_A_INO 0x30
  926. #define PSYCHO_PCIERR_B_INO 0x31
  927. static void psycho_register_error_handlers(struct pci_controller_info *p)
  928. {
  929. struct pci_pbm_info *pbm = &p->pbm_A; /* arbitrary */
  930. unsigned long base = p->pbm_A.controller_regs;
  931. unsigned int irq, portid = pbm->portid;
  932. u64 tmp;
  933. /* Build IRQs and register handlers. */
  934. irq = psycho_irq_build(pbm, NULL, (portid << 6) | PSYCHO_UE_INO);
  935. if (request_irq(irq, psycho_ue_intr,
  936. SA_SHIRQ, "PSYCHO UE", p) < 0) {
  937. prom_printf("PSYCHO%d: Cannot register UE interrupt.\n",
  938. p->index);
  939. prom_halt();
  940. }
  941. irq = psycho_irq_build(pbm, NULL, (portid << 6) | PSYCHO_CE_INO);
  942. if (request_irq(irq, psycho_ce_intr,
  943. SA_SHIRQ, "PSYCHO CE", p) < 0) {
  944. prom_printf("PSYCHO%d: Cannot register CE interrupt.\n",
  945. p->index);
  946. prom_halt();
  947. }
  948. pbm = &p->pbm_A;
  949. irq = psycho_irq_build(pbm, NULL, (portid << 6) | PSYCHO_PCIERR_A_INO);
  950. if (request_irq(irq, psycho_pcierr_intr,
  951. SA_SHIRQ, "PSYCHO PCIERR", &p->pbm_A) < 0) {
  952. prom_printf("PSYCHO%d(PBMA): Cannot register PciERR interrupt.\n",
  953. p->index);
  954. prom_halt();
  955. }
  956. pbm = &p->pbm_B;
  957. irq = psycho_irq_build(pbm, NULL, (portid << 6) | PSYCHO_PCIERR_B_INO);
  958. if (request_irq(irq, psycho_pcierr_intr,
  959. SA_SHIRQ, "PSYCHO PCIERR", &p->pbm_B) < 0) {
  960. prom_printf("PSYCHO%d(PBMB): Cannot register PciERR interrupt.\n",
  961. p->index);
  962. prom_halt();
  963. }
  964. /* Enable UE and CE interrupts for controller. */
  965. psycho_write(base + PSYCHO_ECC_CTRL,
  966. (PSYCHO_ECCCTRL_EE |
  967. PSYCHO_ECCCTRL_UE |
  968. PSYCHO_ECCCTRL_CE));
  969. /* Enable PCI Error interrupts and clear error
  970. * bits for each PBM.
  971. */
  972. tmp = psycho_read(base + PSYCHO_PCIA_CTRL);
  973. tmp |= (PSYCHO_PCICTRL_SERR |
  974. PSYCHO_PCICTRL_SBH_ERR |
  975. PSYCHO_PCICTRL_EEN);
  976. tmp &= ~(PSYCHO_PCICTRL_SBH_INT);
  977. psycho_write(base + PSYCHO_PCIA_CTRL, tmp);
  978. tmp = psycho_read(base + PSYCHO_PCIB_CTRL);
  979. tmp |= (PSYCHO_PCICTRL_SERR |
  980. PSYCHO_PCICTRL_SBH_ERR |
  981. PSYCHO_PCICTRL_EEN);
  982. tmp &= ~(PSYCHO_PCICTRL_SBH_INT);
  983. psycho_write(base + PSYCHO_PCIB_CTRL, tmp);
  984. }
  985. /* PSYCHO boot time probing and initialization. */
  986. static void psycho_resource_adjust(struct pci_dev *pdev,
  987. struct resource *res,
  988. struct resource *root)
  989. {
  990. res->start += root->start;
  991. res->end += root->start;
  992. }
  993. static void psycho_base_address_update(struct pci_dev *pdev, int resource)
  994. {
  995. struct pcidev_cookie *pcp = pdev->sysdata;
  996. struct pci_pbm_info *pbm = pcp->pbm;
  997. struct resource *res, *root;
  998. u32 reg;
  999. int where, size, is_64bit;
  1000. res = &pdev->resource[resource];
  1001. if (resource < 6) {
  1002. where = PCI_BASE_ADDRESS_0 + (resource * 4);
  1003. } else if (resource == PCI_ROM_RESOURCE) {
  1004. where = pdev->rom_base_reg;
  1005. } else {
  1006. /* Somebody might have asked allocation of a non-standard resource */
  1007. return;
  1008. }
  1009. is_64bit = 0;
  1010. if (res->flags & IORESOURCE_IO)
  1011. root = &pbm->io_space;
  1012. else {
  1013. root = &pbm->mem_space;
  1014. if ((res->flags & PCI_BASE_ADDRESS_MEM_TYPE_MASK)
  1015. == PCI_BASE_ADDRESS_MEM_TYPE_64)
  1016. is_64bit = 1;
  1017. }
  1018. size = res->end - res->start;
  1019. pci_read_config_dword(pdev, where, &reg);
  1020. reg = ((reg & size) |
  1021. (((u32)(res->start - root->start)) & ~size));
  1022. if (resource == PCI_ROM_RESOURCE) {
  1023. reg |= PCI_ROM_ADDRESS_ENABLE;
  1024. res->flags |= IORESOURCE_ROM_ENABLE;
  1025. }
  1026. pci_write_config_dword(pdev, where, reg);
  1027. /* This knows that the upper 32-bits of the address
  1028. * must be zero. Our PCI common layer enforces this.
  1029. */
  1030. if (is_64bit)
  1031. pci_write_config_dword(pdev, where + 4, 0);
  1032. }
  1033. static void pbm_config_busmastering(struct pci_pbm_info *pbm)
  1034. {
  1035. u8 *addr;
  1036. /* Set cache-line size to 64 bytes, this is actually
  1037. * a nop but I do it for completeness.
  1038. */
  1039. addr = psycho_pci_config_mkaddr(pbm, pbm->pci_first_busno,
  1040. 0, PCI_CACHE_LINE_SIZE);
  1041. pci_config_write8(addr, 64 / sizeof(u32));
  1042. /* Set PBM latency timer to 64 PCI clocks. */
  1043. addr = psycho_pci_config_mkaddr(pbm, pbm->pci_first_busno,
  1044. 0, PCI_LATENCY_TIMER);
  1045. pci_config_write8(addr, 64);
  1046. }
  1047. static void pbm_scan_bus(struct pci_controller_info *p,
  1048. struct pci_pbm_info *pbm)
  1049. {
  1050. struct pcidev_cookie *cookie = kzalloc(sizeof(*cookie), GFP_KERNEL);
  1051. if (!cookie) {
  1052. prom_printf("PSYCHO: Critical allocation failure.\n");
  1053. prom_halt();
  1054. }
  1055. /* All we care about is the PBM. */
  1056. cookie->pbm = pbm;
  1057. pbm->pci_bus = pci_scan_bus(pbm->pci_first_busno,
  1058. p->pci_ops,
  1059. pbm);
  1060. pci_fixup_host_bridge_self(pbm->pci_bus);
  1061. pbm->pci_bus->self->sysdata = cookie;
  1062. pci_fill_in_pbm_cookies(pbm->pci_bus, pbm, pbm->prom_node);
  1063. pci_record_assignments(pbm, pbm->pci_bus);
  1064. pci_assign_unassigned(pbm, pbm->pci_bus);
  1065. pci_fixup_irq(pbm, pbm->pci_bus);
  1066. pci_determine_66mhz_disposition(pbm, pbm->pci_bus);
  1067. pci_setup_busmastering(pbm, pbm->pci_bus);
  1068. }
  1069. static void psycho_scan_bus(struct pci_controller_info *p)
  1070. {
  1071. pbm_config_busmastering(&p->pbm_B);
  1072. p->pbm_B.is_66mhz_capable = 0;
  1073. pbm_config_busmastering(&p->pbm_A);
  1074. p->pbm_A.is_66mhz_capable = 1;
  1075. pbm_scan_bus(p, &p->pbm_B);
  1076. pbm_scan_bus(p, &p->pbm_A);
  1077. /* After the PCI bus scan is complete, we can register
  1078. * the error interrupt handlers.
  1079. */
  1080. psycho_register_error_handlers(p);
  1081. }
  1082. static void psycho_iommu_init(struct pci_controller_info *p)
  1083. {
  1084. struct pci_iommu *iommu = p->pbm_A.iommu;
  1085. unsigned long i;
  1086. u64 control;
  1087. /* Register addresses. */
  1088. iommu->iommu_control = p->pbm_A.controller_regs + PSYCHO_IOMMU_CONTROL;
  1089. iommu->iommu_tsbbase = p->pbm_A.controller_regs + PSYCHO_IOMMU_TSBBASE;
  1090. iommu->iommu_flush = p->pbm_A.controller_regs + PSYCHO_IOMMU_FLUSH;
  1091. /* PSYCHO's IOMMU lacks ctx flushing. */
  1092. iommu->iommu_ctxflush = 0;
  1093. /* We use the main control register of PSYCHO as the write
  1094. * completion register.
  1095. */
  1096. iommu->write_complete_reg = p->pbm_A.controller_regs + PSYCHO_CONTROL;
  1097. /*
  1098. * Invalidate TLB Entries.
  1099. */
  1100. control = psycho_read(p->pbm_A.controller_regs + PSYCHO_IOMMU_CONTROL);
  1101. control |= PSYCHO_IOMMU_CTRL_DENAB;
  1102. psycho_write(p->pbm_A.controller_regs + PSYCHO_IOMMU_CONTROL, control);
  1103. for(i = 0; i < 16; i++) {
  1104. psycho_write(p->pbm_A.controller_regs + PSYCHO_IOMMU_TAG + (i * 8UL), 0);
  1105. psycho_write(p->pbm_A.controller_regs + PSYCHO_IOMMU_DATA + (i * 8UL), 0);
  1106. }
  1107. /* Leave diag mode enabled for full-flushing done
  1108. * in pci_iommu.c
  1109. */
  1110. pci_iommu_table_init(iommu, IO_TSB_SIZE, 0xc0000000, 0xffffffff);
  1111. psycho_write(p->pbm_A.controller_regs + PSYCHO_IOMMU_TSBBASE,
  1112. __pa(iommu->page_table));
  1113. control = psycho_read(p->pbm_A.controller_regs + PSYCHO_IOMMU_CONTROL);
  1114. control &= ~(PSYCHO_IOMMU_CTRL_TSBSZ | PSYCHO_IOMMU_CTRL_TBWSZ);
  1115. control |= (PSYCHO_IOMMU_TSBSZ_128K | PSYCHO_IOMMU_CTRL_ENAB);
  1116. psycho_write(p->pbm_A.controller_regs + PSYCHO_IOMMU_CONTROL, control);
  1117. /* If necessary, hook us up for starfire IRQ translations. */
  1118. if (this_is_starfire)
  1119. p->starfire_cookie = starfire_hookup(p->pbm_A.portid);
  1120. else
  1121. p->starfire_cookie = NULL;
  1122. }
  1123. #define PSYCHO_IRQ_RETRY 0x1a00UL
  1124. #define PSYCHO_PCIA_DIAG 0x2020UL
  1125. #define PSYCHO_PCIB_DIAG 0x4020UL
  1126. #define PSYCHO_PCIDIAG_RESV 0xffffffffffffff80UL /* Reserved */
  1127. #define PSYCHO_PCIDIAG_DRETRY 0x0000000000000040UL /* Disable retry limit */
  1128. #define PSYCHO_PCIDIAG_DISYNC 0x0000000000000020UL /* Disable DMA wr / irq sync */
  1129. #define PSYCHO_PCIDIAG_DDWSYNC 0x0000000000000010UL /* Disable DMA wr / PIO rd sync */
  1130. #define PSYCHO_PCIDIAG_IDDPAR 0x0000000000000008UL /* Invert DMA data parity */
  1131. #define PSYCHO_PCIDIAG_IPDPAR 0x0000000000000004UL /* Invert PIO data parity */
  1132. #define PSYCHO_PCIDIAG_IPAPAR 0x0000000000000002UL /* Invert PIO address parity */
  1133. #define PSYCHO_PCIDIAG_LPBACK 0x0000000000000001UL /* Enable loopback mode */
  1134. static void psycho_controller_hwinit(struct pci_controller_info *p)
  1135. {
  1136. u64 tmp;
  1137. psycho_write(p->pbm_A.controller_regs + PSYCHO_IRQ_RETRY, 5);
  1138. /* Enable arbiter for all PCI slots. */
  1139. tmp = psycho_read(p->pbm_A.controller_regs + PSYCHO_PCIA_CTRL);
  1140. tmp |= PSYCHO_PCICTRL_AEN;
  1141. psycho_write(p->pbm_A.controller_regs + PSYCHO_PCIA_CTRL, tmp);
  1142. tmp = psycho_read(p->pbm_A.controller_regs + PSYCHO_PCIB_CTRL);
  1143. tmp |= PSYCHO_PCICTRL_AEN;
  1144. psycho_write(p->pbm_A.controller_regs + PSYCHO_PCIB_CTRL, tmp);
  1145. /* Disable DMA write / PIO read synchronization on
  1146. * both PCI bus segments.
  1147. * [ U2P Erratum 1243770, STP2223BGA data sheet ]
  1148. */
  1149. tmp = psycho_read(p->pbm_A.controller_regs + PSYCHO_PCIA_DIAG);
  1150. tmp |= PSYCHO_PCIDIAG_DDWSYNC;
  1151. psycho_write(p->pbm_A.controller_regs + PSYCHO_PCIA_DIAG, tmp);
  1152. tmp = psycho_read(p->pbm_A.controller_regs + PSYCHO_PCIB_DIAG);
  1153. tmp |= PSYCHO_PCIDIAG_DDWSYNC;
  1154. psycho_write(p->pbm_A.controller_regs + PSYCHO_PCIB_DIAG, tmp);
  1155. }
  1156. static void pbm_register_toplevel_resources(struct pci_controller_info *p,
  1157. struct pci_pbm_info *pbm)
  1158. {
  1159. char *name = pbm->name;
  1160. sprintf(name, "PSYCHO%d PBM%c",
  1161. p->index,
  1162. (pbm == &p->pbm_A ? 'A' : 'B'));
  1163. pbm->io_space.name = pbm->mem_space.name = name;
  1164. request_resource(&ioport_resource, &pbm->io_space);
  1165. request_resource(&iomem_resource, &pbm->mem_space);
  1166. pci_register_legacy_regions(&pbm->io_space,
  1167. &pbm->mem_space);
  1168. }
  1169. static void psycho_pbm_strbuf_init(struct pci_controller_info *p,
  1170. struct pci_pbm_info *pbm,
  1171. int is_pbm_a)
  1172. {
  1173. unsigned long base = pbm->controller_regs;
  1174. u64 control;
  1175. if (is_pbm_a) {
  1176. pbm->stc.strbuf_control = base + PSYCHO_STRBUF_CONTROL_A;
  1177. pbm->stc.strbuf_pflush = base + PSYCHO_STRBUF_FLUSH_A;
  1178. pbm->stc.strbuf_fsync = base + PSYCHO_STRBUF_FSYNC_A;
  1179. } else {
  1180. pbm->stc.strbuf_control = base + PSYCHO_STRBUF_CONTROL_B;
  1181. pbm->stc.strbuf_pflush = base + PSYCHO_STRBUF_FLUSH_B;
  1182. pbm->stc.strbuf_fsync = base + PSYCHO_STRBUF_FSYNC_B;
  1183. }
  1184. /* PSYCHO's streaming buffer lacks ctx flushing. */
  1185. pbm->stc.strbuf_ctxflush = 0;
  1186. pbm->stc.strbuf_ctxmatch_base = 0;
  1187. pbm->stc.strbuf_flushflag = (volatile unsigned long *)
  1188. ((((unsigned long)&pbm->stc.__flushflag_buf[0])
  1189. + 63UL)
  1190. & ~63UL);
  1191. pbm->stc.strbuf_flushflag_pa = (unsigned long)
  1192. __pa(pbm->stc.strbuf_flushflag);
  1193. /* Enable the streaming buffer. We have to be careful
  1194. * just in case OBP left it with LRU locking enabled.
  1195. *
  1196. * It is possible to control if PBM will be rerun on
  1197. * line misses. Currently I just retain whatever setting
  1198. * OBP left us with. All checks so far show it having
  1199. * a value of zero.
  1200. */
  1201. #undef PSYCHO_STRBUF_RERUN_ENABLE
  1202. #undef PSYCHO_STRBUF_RERUN_DISABLE
  1203. control = psycho_read(pbm->stc.strbuf_control);
  1204. control |= PSYCHO_STRBUF_CTRL_ENAB;
  1205. control &= ~(PSYCHO_STRBUF_CTRL_LENAB | PSYCHO_STRBUF_CTRL_LPTR);
  1206. #ifdef PSYCHO_STRBUF_RERUN_ENABLE
  1207. control &= ~(PSYCHO_STRBUF_CTRL_RRDIS);
  1208. #else
  1209. #ifdef PSYCHO_STRBUF_RERUN_DISABLE
  1210. control |= PSYCHO_STRBUF_CTRL_RRDIS;
  1211. #endif
  1212. #endif
  1213. psycho_write(pbm->stc.strbuf_control, control);
  1214. pbm->stc.strbuf_enabled = 1;
  1215. }
  1216. #define PSYCHO_IOSPACE_A 0x002000000UL
  1217. #define PSYCHO_IOSPACE_B 0x002010000UL
  1218. #define PSYCHO_IOSPACE_SIZE 0x00000ffffUL
  1219. #define PSYCHO_MEMSPACE_A 0x100000000UL
  1220. #define PSYCHO_MEMSPACE_B 0x180000000UL
  1221. #define PSYCHO_MEMSPACE_SIZE 0x07fffffffUL
  1222. static void psycho_pbm_init(struct pci_controller_info *p,
  1223. int prom_node, int is_pbm_a)
  1224. {
  1225. unsigned int busrange[2];
  1226. struct pci_pbm_info *pbm;
  1227. int err;
  1228. if (is_pbm_a) {
  1229. pbm = &p->pbm_A;
  1230. pbm->pci_first_slot = 1;
  1231. pbm->io_space.start = pbm->controller_regs + PSYCHO_IOSPACE_A;
  1232. pbm->mem_space.start = pbm->controller_regs + PSYCHO_MEMSPACE_A;
  1233. } else {
  1234. pbm = &p->pbm_B;
  1235. pbm->pci_first_slot = 2;
  1236. pbm->io_space.start = pbm->controller_regs + PSYCHO_IOSPACE_B;
  1237. pbm->mem_space.start = pbm->controller_regs + PSYCHO_MEMSPACE_B;
  1238. }
  1239. pbm->chip_type = PBM_CHIP_TYPE_PSYCHO;
  1240. pbm->chip_version =
  1241. prom_getintdefault(prom_node, "version#", 0);
  1242. pbm->chip_revision =
  1243. prom_getintdefault(prom_node, "module-revision#", 0);
  1244. pbm->io_space.end = pbm->io_space.start + PSYCHO_IOSPACE_SIZE;
  1245. pbm->io_space.flags = IORESOURCE_IO;
  1246. pbm->mem_space.end = pbm->mem_space.start + PSYCHO_MEMSPACE_SIZE;
  1247. pbm->mem_space.flags = IORESOURCE_MEM;
  1248. pbm_register_toplevel_resources(p, pbm);
  1249. pbm->parent = p;
  1250. pbm->prom_node = prom_node;
  1251. prom_getstring(prom_node, "name",
  1252. pbm->prom_name,
  1253. sizeof(pbm->prom_name));
  1254. err = prom_getproperty(prom_node, "ranges",
  1255. (char *)pbm->pbm_ranges,
  1256. sizeof(pbm->pbm_ranges));
  1257. if (err != -1)
  1258. pbm->num_pbm_ranges =
  1259. (err / sizeof(struct linux_prom_pci_ranges));
  1260. else
  1261. pbm->num_pbm_ranges = 0;
  1262. err = prom_getproperty(prom_node, "interrupt-map",
  1263. (char *)pbm->pbm_intmap,
  1264. sizeof(pbm->pbm_intmap));
  1265. if (err != -1) {
  1266. pbm->num_pbm_intmap = (err / sizeof(struct linux_prom_pci_intmap));
  1267. err = prom_getproperty(prom_node, "interrupt-map-mask",
  1268. (char *)&pbm->pbm_intmask,
  1269. sizeof(pbm->pbm_intmask));
  1270. if (err == -1) {
  1271. prom_printf("PSYCHO-PBM: Fatal error, no "
  1272. "interrupt-map-mask.\n");
  1273. prom_halt();
  1274. }
  1275. } else {
  1276. pbm->num_pbm_intmap = 0;
  1277. memset(&pbm->pbm_intmask, 0, sizeof(pbm->pbm_intmask));
  1278. }
  1279. err = prom_getproperty(prom_node, "bus-range",
  1280. (char *)&busrange[0],
  1281. sizeof(busrange));
  1282. if (err == 0 || err == -1) {
  1283. prom_printf("PSYCHO-PBM: Fatal error, no bus-range.\n");
  1284. prom_halt();
  1285. }
  1286. pbm->pci_first_busno = busrange[0];
  1287. pbm->pci_last_busno = busrange[1];
  1288. psycho_pbm_strbuf_init(p, pbm, is_pbm_a);
  1289. }
  1290. #define PSYCHO_CONFIGSPACE 0x001000000UL
  1291. void psycho_init(int node, char *model_name)
  1292. {
  1293. struct linux_prom64_registers pr_regs[3];
  1294. struct pci_controller_info *p;
  1295. struct pci_iommu *iommu;
  1296. u32 upa_portid;
  1297. int is_pbm_a, err;
  1298. upa_portid = prom_getintdefault(node, "upa-portid", 0xff);
  1299. for(p = pci_controller_root; p; p = p->next) {
  1300. if (p->pbm_A.portid == upa_portid) {
  1301. is_pbm_a = (p->pbm_A.prom_node == 0);
  1302. psycho_pbm_init(p, node, is_pbm_a);
  1303. return;
  1304. }
  1305. }
  1306. p = kzalloc(sizeof(struct pci_controller_info), GFP_ATOMIC);
  1307. if (!p) {
  1308. prom_printf("PSYCHO: Fatal memory allocation error.\n");
  1309. prom_halt();
  1310. }
  1311. iommu = kzalloc(sizeof(struct pci_iommu), GFP_ATOMIC);
  1312. if (!iommu) {
  1313. prom_printf("PSYCHO: Fatal memory allocation error.\n");
  1314. prom_halt();
  1315. }
  1316. p->pbm_A.iommu = p->pbm_B.iommu = iommu;
  1317. p->next = pci_controller_root;
  1318. pci_controller_root = p;
  1319. p->pbm_A.portid = upa_portid;
  1320. p->pbm_B.portid = upa_portid;
  1321. p->index = pci_num_controllers++;
  1322. p->pbms_same_domain = 0;
  1323. p->scan_bus = psycho_scan_bus;
  1324. p->irq_build = psycho_irq_build;
  1325. p->base_address_update = psycho_base_address_update;
  1326. p->resource_adjust = psycho_resource_adjust;
  1327. p->pci_ops = &psycho_ops;
  1328. err = prom_getproperty(node, "reg",
  1329. (char *)&pr_regs[0],
  1330. sizeof(pr_regs));
  1331. if (err == 0 || err == -1) {
  1332. prom_printf("PSYCHO: Fatal error, no reg property.\n");
  1333. prom_halt();
  1334. }
  1335. p->pbm_A.controller_regs = pr_regs[2].phys_addr;
  1336. p->pbm_B.controller_regs = pr_regs[2].phys_addr;
  1337. printk("PCI: Found PSYCHO, control regs at %016lx\n",
  1338. p->pbm_A.controller_regs);
  1339. p->pbm_A.config_space = p->pbm_B.config_space =
  1340. (pr_regs[2].phys_addr + PSYCHO_CONFIGSPACE);
  1341. printk("PSYCHO: Shared PCI config space at %016lx\n",
  1342. p->pbm_A.config_space);
  1343. /*
  1344. * Psycho's PCI MEM space is mapped to a 2GB aligned area, so
  1345. * we need to adjust our MEM space mask.
  1346. */
  1347. pci_memspace_mask = 0x7fffffffUL;
  1348. psycho_controller_hwinit(p);
  1349. psycho_iommu_init(p);
  1350. is_pbm_a = ((pr_regs[0].phys_addr & 0x6000) == 0x2000);
  1351. psycho_pbm_init(p, node, is_pbm_a);
  1352. }