pci_psycho.c 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559
  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*/4, /* 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*/4, /* second SCSI */
  267. /*0x27*/11, /* Floppy */
  268. /*0x28*/4, /* Spare Hardware */
  269. /*0x29*/9, /* Keyboard */
  270. /*0x2a*/4, /* 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 = 4;
  286. } else if (ret == 0) {
  287. switch ((pdev->class >> 16) & 0xff) {
  288. case PCI_BASE_CLASS_STORAGE:
  289. ret = 4;
  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 = 4;
  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 = kmalloc(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. memset(cookie, 0, sizeof(*cookie));
  1057. cookie->pbm = pbm;
  1058. pbm->pci_bus = pci_scan_bus(pbm->pci_first_busno,
  1059. p->pci_ops,
  1060. pbm);
  1061. pci_fixup_host_bridge_self(pbm->pci_bus);
  1062. pbm->pci_bus->self->sysdata = cookie;
  1063. pci_fill_in_pbm_cookies(pbm->pci_bus, pbm, pbm->prom_node);
  1064. pci_record_assignments(pbm, pbm->pci_bus);
  1065. pci_assign_unassigned(pbm, pbm->pci_bus);
  1066. pci_fixup_irq(pbm, pbm->pci_bus);
  1067. pci_determine_66mhz_disposition(pbm, pbm->pci_bus);
  1068. pci_setup_busmastering(pbm, pbm->pci_bus);
  1069. }
  1070. static void psycho_scan_bus(struct pci_controller_info *p)
  1071. {
  1072. pbm_config_busmastering(&p->pbm_B);
  1073. p->pbm_B.is_66mhz_capable = 0;
  1074. pbm_config_busmastering(&p->pbm_A);
  1075. p->pbm_A.is_66mhz_capable = 1;
  1076. pbm_scan_bus(p, &p->pbm_B);
  1077. pbm_scan_bus(p, &p->pbm_A);
  1078. /* After the PCI bus scan is complete, we can register
  1079. * the error interrupt handlers.
  1080. */
  1081. psycho_register_error_handlers(p);
  1082. }
  1083. static void psycho_iommu_init(struct pci_controller_info *p)
  1084. {
  1085. struct pci_iommu *iommu = p->pbm_A.iommu;
  1086. unsigned long tsbbase, i;
  1087. u64 control;
  1088. /* Setup initial software IOMMU state. */
  1089. spin_lock_init(&iommu->lock);
  1090. iommu->ctx_lowest_free = 1;
  1091. /* Register addresses. */
  1092. iommu->iommu_control = p->pbm_A.controller_regs + PSYCHO_IOMMU_CONTROL;
  1093. iommu->iommu_tsbbase = p->pbm_A.controller_regs + PSYCHO_IOMMU_TSBBASE;
  1094. iommu->iommu_flush = p->pbm_A.controller_regs + PSYCHO_IOMMU_FLUSH;
  1095. /* PSYCHO's IOMMU lacks ctx flushing. */
  1096. iommu->iommu_ctxflush = 0;
  1097. /* We use the main control register of PSYCHO as the write
  1098. * completion register.
  1099. */
  1100. iommu->write_complete_reg = p->pbm_A.controller_regs + PSYCHO_CONTROL;
  1101. /*
  1102. * Invalidate TLB Entries.
  1103. */
  1104. control = psycho_read(p->pbm_A.controller_regs + PSYCHO_IOMMU_CONTROL);
  1105. control |= PSYCHO_IOMMU_CTRL_DENAB;
  1106. psycho_write(p->pbm_A.controller_regs + PSYCHO_IOMMU_CONTROL, control);
  1107. for(i = 0; i < 16; i++) {
  1108. psycho_write(p->pbm_A.controller_regs + PSYCHO_IOMMU_TAG + (i * 8UL), 0);
  1109. psycho_write(p->pbm_A.controller_regs + PSYCHO_IOMMU_DATA + (i * 8UL), 0);
  1110. }
  1111. /* Leave diag mode enabled for full-flushing done
  1112. * in pci_iommu.c
  1113. */
  1114. iommu->dummy_page = __get_free_pages(GFP_KERNEL, 0);
  1115. if (!iommu->dummy_page) {
  1116. prom_printf("PSYCHO_IOMMU: Error, gfp(dummy_page) failed.\n");
  1117. prom_halt();
  1118. }
  1119. memset((void *)iommu->dummy_page, 0, PAGE_SIZE);
  1120. iommu->dummy_page_pa = (unsigned long) __pa(iommu->dummy_page);
  1121. /* Using assumed page size 8K with 128K entries we need 1MB iommu page
  1122. * table (128K ioptes * 8 bytes per iopte). This is
  1123. * page order 7 on UltraSparc.
  1124. */
  1125. tsbbase = __get_free_pages(GFP_KERNEL, get_order(IO_TSB_SIZE));
  1126. if (!tsbbase) {
  1127. prom_printf("PSYCHO_IOMMU: Error, gfp(tsb) failed.\n");
  1128. prom_halt();
  1129. }
  1130. iommu->page_table = (iopte_t *)tsbbase;
  1131. iommu->page_table_sz_bits = 17;
  1132. iommu->page_table_map_base = 0xc0000000;
  1133. iommu->dma_addr_mask = 0xffffffff;
  1134. pci_iommu_table_init(iommu, IO_TSB_SIZE);
  1135. /* We start with no consistent mappings. */
  1136. iommu->lowest_consistent_map =
  1137. 1 << (iommu->page_table_sz_bits - PBM_LOGCLUSTERS);
  1138. for (i = 0; i < PBM_NCLUSTERS; i++) {
  1139. iommu->alloc_info[i].flush = 0;
  1140. iommu->alloc_info[i].next = 0;
  1141. }
  1142. psycho_write(p->pbm_A.controller_regs + PSYCHO_IOMMU_TSBBASE, __pa(tsbbase));
  1143. control = psycho_read(p->pbm_A.controller_regs + PSYCHO_IOMMU_CONTROL);
  1144. control &= ~(PSYCHO_IOMMU_CTRL_TSBSZ | PSYCHO_IOMMU_CTRL_TBWSZ);
  1145. control |= (PSYCHO_IOMMU_TSBSZ_128K | PSYCHO_IOMMU_CTRL_ENAB);
  1146. psycho_write(p->pbm_A.controller_regs + PSYCHO_IOMMU_CONTROL, control);
  1147. /* If necessary, hook us up for starfire IRQ translations. */
  1148. if(this_is_starfire)
  1149. p->starfire_cookie = starfire_hookup(p->pbm_A.portid);
  1150. else
  1151. p->starfire_cookie = NULL;
  1152. }
  1153. #define PSYCHO_IRQ_RETRY 0x1a00UL
  1154. #define PSYCHO_PCIA_DIAG 0x2020UL
  1155. #define PSYCHO_PCIB_DIAG 0x4020UL
  1156. #define PSYCHO_PCIDIAG_RESV 0xffffffffffffff80UL /* Reserved */
  1157. #define PSYCHO_PCIDIAG_DRETRY 0x0000000000000040UL /* Disable retry limit */
  1158. #define PSYCHO_PCIDIAG_DISYNC 0x0000000000000020UL /* Disable DMA wr / irq sync */
  1159. #define PSYCHO_PCIDIAG_DDWSYNC 0x0000000000000010UL /* Disable DMA wr / PIO rd sync */
  1160. #define PSYCHO_PCIDIAG_IDDPAR 0x0000000000000008UL /* Invert DMA data parity */
  1161. #define PSYCHO_PCIDIAG_IPDPAR 0x0000000000000004UL /* Invert PIO data parity */
  1162. #define PSYCHO_PCIDIAG_IPAPAR 0x0000000000000002UL /* Invert PIO address parity */
  1163. #define PSYCHO_PCIDIAG_LPBACK 0x0000000000000001UL /* Enable loopback mode */
  1164. static void psycho_controller_hwinit(struct pci_controller_info *p)
  1165. {
  1166. u64 tmp;
  1167. psycho_write(p->pbm_A.controller_regs + PSYCHO_IRQ_RETRY, 5);
  1168. /* Enable arbiter for all PCI slots. */
  1169. tmp = psycho_read(p->pbm_A.controller_regs + PSYCHO_PCIA_CTRL);
  1170. tmp |= PSYCHO_PCICTRL_AEN;
  1171. psycho_write(p->pbm_A.controller_regs + PSYCHO_PCIA_CTRL, tmp);
  1172. tmp = psycho_read(p->pbm_A.controller_regs + PSYCHO_PCIB_CTRL);
  1173. tmp |= PSYCHO_PCICTRL_AEN;
  1174. psycho_write(p->pbm_A.controller_regs + PSYCHO_PCIB_CTRL, tmp);
  1175. /* Disable DMA write / PIO read synchronization on
  1176. * both PCI bus segments.
  1177. * [ U2P Erratum 1243770, STP2223BGA data sheet ]
  1178. */
  1179. tmp = psycho_read(p->pbm_A.controller_regs + PSYCHO_PCIA_DIAG);
  1180. tmp |= PSYCHO_PCIDIAG_DDWSYNC;
  1181. psycho_write(p->pbm_A.controller_regs + PSYCHO_PCIA_DIAG, tmp);
  1182. tmp = psycho_read(p->pbm_A.controller_regs + PSYCHO_PCIB_DIAG);
  1183. tmp |= PSYCHO_PCIDIAG_DDWSYNC;
  1184. psycho_write(p->pbm_A.controller_regs + PSYCHO_PCIB_DIAG, tmp);
  1185. }
  1186. static void pbm_register_toplevel_resources(struct pci_controller_info *p,
  1187. struct pci_pbm_info *pbm)
  1188. {
  1189. char *name = pbm->name;
  1190. sprintf(name, "PSYCHO%d PBM%c",
  1191. p->index,
  1192. (pbm == &p->pbm_A ? 'A' : 'B'));
  1193. pbm->io_space.name = pbm->mem_space.name = name;
  1194. request_resource(&ioport_resource, &pbm->io_space);
  1195. request_resource(&iomem_resource, &pbm->mem_space);
  1196. pci_register_legacy_regions(&pbm->io_space,
  1197. &pbm->mem_space);
  1198. }
  1199. static void psycho_pbm_strbuf_init(struct pci_controller_info *p,
  1200. struct pci_pbm_info *pbm,
  1201. int is_pbm_a)
  1202. {
  1203. unsigned long base = pbm->controller_regs;
  1204. u64 control;
  1205. if (is_pbm_a) {
  1206. pbm->stc.strbuf_control = base + PSYCHO_STRBUF_CONTROL_A;
  1207. pbm->stc.strbuf_pflush = base + PSYCHO_STRBUF_FLUSH_A;
  1208. pbm->stc.strbuf_fsync = base + PSYCHO_STRBUF_FSYNC_A;
  1209. } else {
  1210. pbm->stc.strbuf_control = base + PSYCHO_STRBUF_CONTROL_B;
  1211. pbm->stc.strbuf_pflush = base + PSYCHO_STRBUF_FLUSH_B;
  1212. pbm->stc.strbuf_fsync = base + PSYCHO_STRBUF_FSYNC_B;
  1213. }
  1214. /* PSYCHO's streaming buffer lacks ctx flushing. */
  1215. pbm->stc.strbuf_ctxflush = 0;
  1216. pbm->stc.strbuf_ctxmatch_base = 0;
  1217. pbm->stc.strbuf_flushflag = (volatile unsigned long *)
  1218. ((((unsigned long)&pbm->stc.__flushflag_buf[0])
  1219. + 63UL)
  1220. & ~63UL);
  1221. pbm->stc.strbuf_flushflag_pa = (unsigned long)
  1222. __pa(pbm->stc.strbuf_flushflag);
  1223. /* Enable the streaming buffer. We have to be careful
  1224. * just in case OBP left it with LRU locking enabled.
  1225. *
  1226. * It is possible to control if PBM will be rerun on
  1227. * line misses. Currently I just retain whatever setting
  1228. * OBP left us with. All checks so far show it having
  1229. * a value of zero.
  1230. */
  1231. #undef PSYCHO_STRBUF_RERUN_ENABLE
  1232. #undef PSYCHO_STRBUF_RERUN_DISABLE
  1233. control = psycho_read(pbm->stc.strbuf_control);
  1234. control |= PSYCHO_STRBUF_CTRL_ENAB;
  1235. control &= ~(PSYCHO_STRBUF_CTRL_LENAB | PSYCHO_STRBUF_CTRL_LPTR);
  1236. #ifdef PSYCHO_STRBUF_RERUN_ENABLE
  1237. control &= ~(PSYCHO_STRBUF_CTRL_RRDIS);
  1238. #else
  1239. #ifdef PSYCHO_STRBUF_RERUN_DISABLE
  1240. control |= PSYCHO_STRBUF_CTRL_RRDIS;
  1241. #endif
  1242. #endif
  1243. psycho_write(pbm->stc.strbuf_control, control);
  1244. pbm->stc.strbuf_enabled = 1;
  1245. }
  1246. #define PSYCHO_IOSPACE_A 0x002000000UL
  1247. #define PSYCHO_IOSPACE_B 0x002010000UL
  1248. #define PSYCHO_IOSPACE_SIZE 0x00000ffffUL
  1249. #define PSYCHO_MEMSPACE_A 0x100000000UL
  1250. #define PSYCHO_MEMSPACE_B 0x180000000UL
  1251. #define PSYCHO_MEMSPACE_SIZE 0x07fffffffUL
  1252. static void psycho_pbm_init(struct pci_controller_info *p,
  1253. int prom_node, int is_pbm_a)
  1254. {
  1255. unsigned int busrange[2];
  1256. struct pci_pbm_info *pbm;
  1257. int err;
  1258. if (is_pbm_a) {
  1259. pbm = &p->pbm_A;
  1260. pbm->pci_first_slot = 1;
  1261. pbm->io_space.start = pbm->controller_regs + PSYCHO_IOSPACE_A;
  1262. pbm->mem_space.start = pbm->controller_regs + PSYCHO_MEMSPACE_A;
  1263. } else {
  1264. pbm = &p->pbm_B;
  1265. pbm->pci_first_slot = 2;
  1266. pbm->io_space.start = pbm->controller_regs + PSYCHO_IOSPACE_B;
  1267. pbm->mem_space.start = pbm->controller_regs + PSYCHO_MEMSPACE_B;
  1268. }
  1269. pbm->chip_type = PBM_CHIP_TYPE_PSYCHO;
  1270. pbm->chip_version =
  1271. prom_getintdefault(prom_node, "version#", 0);
  1272. pbm->chip_revision =
  1273. prom_getintdefault(prom_node, "module-revision#", 0);
  1274. pbm->io_space.end = pbm->io_space.start + PSYCHO_IOSPACE_SIZE;
  1275. pbm->io_space.flags = IORESOURCE_IO;
  1276. pbm->mem_space.end = pbm->mem_space.start + PSYCHO_MEMSPACE_SIZE;
  1277. pbm->mem_space.flags = IORESOURCE_MEM;
  1278. pbm_register_toplevel_resources(p, pbm);
  1279. pbm->parent = p;
  1280. pbm->prom_node = prom_node;
  1281. prom_getstring(prom_node, "name",
  1282. pbm->prom_name,
  1283. sizeof(pbm->prom_name));
  1284. err = prom_getproperty(prom_node, "ranges",
  1285. (char *)pbm->pbm_ranges,
  1286. sizeof(pbm->pbm_ranges));
  1287. if (err != -1)
  1288. pbm->num_pbm_ranges =
  1289. (err / sizeof(struct linux_prom_pci_ranges));
  1290. else
  1291. pbm->num_pbm_ranges = 0;
  1292. err = prom_getproperty(prom_node, "interrupt-map",
  1293. (char *)pbm->pbm_intmap,
  1294. sizeof(pbm->pbm_intmap));
  1295. if (err != -1) {
  1296. pbm->num_pbm_intmap = (err / sizeof(struct linux_prom_pci_intmap));
  1297. err = prom_getproperty(prom_node, "interrupt-map-mask",
  1298. (char *)&pbm->pbm_intmask,
  1299. sizeof(pbm->pbm_intmask));
  1300. if (err == -1) {
  1301. prom_printf("PSYCHO-PBM: Fatal error, no "
  1302. "interrupt-map-mask.\n");
  1303. prom_halt();
  1304. }
  1305. } else {
  1306. pbm->num_pbm_intmap = 0;
  1307. memset(&pbm->pbm_intmask, 0, sizeof(pbm->pbm_intmask));
  1308. }
  1309. err = prom_getproperty(prom_node, "bus-range",
  1310. (char *)&busrange[0],
  1311. sizeof(busrange));
  1312. if (err == 0 || err == -1) {
  1313. prom_printf("PSYCHO-PBM: Fatal error, no bus-range.\n");
  1314. prom_halt();
  1315. }
  1316. pbm->pci_first_busno = busrange[0];
  1317. pbm->pci_last_busno = busrange[1];
  1318. psycho_pbm_strbuf_init(p, pbm, is_pbm_a);
  1319. }
  1320. #define PSYCHO_CONFIGSPACE 0x001000000UL
  1321. void psycho_init(int node, char *model_name)
  1322. {
  1323. struct linux_prom64_registers pr_regs[3];
  1324. struct pci_controller_info *p;
  1325. struct pci_iommu *iommu;
  1326. u32 upa_portid;
  1327. int is_pbm_a, err;
  1328. upa_portid = prom_getintdefault(node, "upa-portid", 0xff);
  1329. for(p = pci_controller_root; p; p = p->next) {
  1330. if (p->pbm_A.portid == upa_portid) {
  1331. is_pbm_a = (p->pbm_A.prom_node == 0);
  1332. psycho_pbm_init(p, node, is_pbm_a);
  1333. return;
  1334. }
  1335. }
  1336. p = kmalloc(sizeof(struct pci_controller_info), GFP_ATOMIC);
  1337. if (!p) {
  1338. prom_printf("PSYCHO: Fatal memory allocation error.\n");
  1339. prom_halt();
  1340. }
  1341. memset(p, 0, sizeof(*p));
  1342. iommu = kmalloc(sizeof(struct pci_iommu), GFP_ATOMIC);
  1343. if (!iommu) {
  1344. prom_printf("PSYCHO: Fatal memory allocation error.\n");
  1345. prom_halt();
  1346. }
  1347. memset(iommu, 0, sizeof(*iommu));
  1348. p->pbm_A.iommu = p->pbm_B.iommu = iommu;
  1349. p->next = pci_controller_root;
  1350. pci_controller_root = p;
  1351. p->pbm_A.portid = upa_portid;
  1352. p->pbm_B.portid = upa_portid;
  1353. p->index = pci_num_controllers++;
  1354. p->pbms_same_domain = 0;
  1355. p->scan_bus = psycho_scan_bus;
  1356. p->irq_build = psycho_irq_build;
  1357. p->base_address_update = psycho_base_address_update;
  1358. p->resource_adjust = psycho_resource_adjust;
  1359. p->pci_ops = &psycho_ops;
  1360. err = prom_getproperty(node, "reg",
  1361. (char *)&pr_regs[0],
  1362. sizeof(pr_regs));
  1363. if (err == 0 || err == -1) {
  1364. prom_printf("PSYCHO: Fatal error, no reg property.\n");
  1365. prom_halt();
  1366. }
  1367. p->pbm_A.controller_regs = pr_regs[2].phys_addr;
  1368. p->pbm_B.controller_regs = pr_regs[2].phys_addr;
  1369. printk("PCI: Found PSYCHO, control regs at %016lx\n",
  1370. p->pbm_A.controller_regs);
  1371. p->pbm_A.config_space = p->pbm_B.config_space =
  1372. (pr_regs[2].phys_addr + PSYCHO_CONFIGSPACE);
  1373. printk("PSYCHO: Shared PCI config space at %016lx\n",
  1374. p->pbm_A.config_space);
  1375. /*
  1376. * Psycho's PCI MEM space is mapped to a 2GB aligned area, so
  1377. * we need to adjust our MEM space mask.
  1378. */
  1379. pci_memspace_mask = 0x7fffffffUL;
  1380. psycho_controller_hwinit(p);
  1381. psycho_iommu_init(p);
  1382. is_pbm_a = ((pr_regs[0].phys_addr & 0x6000) == 0x2000);
  1383. psycho_pbm_init(p, node, is_pbm_a);
  1384. }