pci_schizo.c 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646
  1. /* pci_schizo.c: SCHIZO/TOMATILLO specific PCI controller support.
  2. *
  3. * Copyright (C) 2001, 2002, 2003, 2007 David S. Miller (davem@davemloft.net)
  4. */
  5. #include <linux/kernel.h>
  6. #include <linux/types.h>
  7. #include <linux/pci.h>
  8. #include <linux/init.h>
  9. #include <linux/slab.h>
  10. #include <linux/interrupt.h>
  11. #include <asm/pbm.h>
  12. #include <asm/iommu.h>
  13. #include <asm/irq.h>
  14. #include <asm/upa.h>
  15. #include <asm/pstate.h>
  16. #include <asm/prom.h>
  17. #include "pci_impl.h"
  18. #include "iommu_common.h"
  19. /* All SCHIZO registers are 64-bits. The following accessor
  20. * routines are how they are accessed. The REG parameter
  21. * is a physical address.
  22. */
  23. #define schizo_read(__reg) \
  24. ({ u64 __ret; \
  25. __asm__ __volatile__("ldxa [%1] %2, %0" \
  26. : "=r" (__ret) \
  27. : "r" (__reg), "i" (ASI_PHYS_BYPASS_EC_E) \
  28. : "memory"); \
  29. __ret; \
  30. })
  31. #define schizo_write(__reg, __val) \
  32. __asm__ __volatile__("stxa %0, [%1] %2" \
  33. : /* no outputs */ \
  34. : "r" (__val), "r" (__reg), \
  35. "i" (ASI_PHYS_BYPASS_EC_E) \
  36. : "memory")
  37. /* This is a convention that at least Excalibur and Merlin
  38. * follow. I suppose the SCHIZO used in Starcat and friends
  39. * will do similar.
  40. *
  41. * The only way I could see this changing is if the newlink
  42. * block requires more space in Schizo's address space than
  43. * they predicted, thus requiring an address space reorg when
  44. * the newer Schizo is taped out.
  45. */
  46. /* Streaming buffer control register. */
  47. #define SCHIZO_STRBUF_CTRL_LPTR 0x00000000000000f0UL /* LRU Lock Pointer */
  48. #define SCHIZO_STRBUF_CTRL_LENAB 0x0000000000000008UL /* LRU Lock Enable */
  49. #define SCHIZO_STRBUF_CTRL_RRDIS 0x0000000000000004UL /* Rerun Disable */
  50. #define SCHIZO_STRBUF_CTRL_DENAB 0x0000000000000002UL /* Diagnostic Mode Enable */
  51. #define SCHIZO_STRBUF_CTRL_ENAB 0x0000000000000001UL /* Streaming Buffer Enable */
  52. /* IOMMU control register. */
  53. #define SCHIZO_IOMMU_CTRL_RESV 0xfffffffff9000000UL /* Reserved */
  54. #define SCHIZO_IOMMU_CTRL_XLTESTAT 0x0000000006000000UL /* Translation Error Status */
  55. #define SCHIZO_IOMMU_CTRL_XLTEERR 0x0000000001000000UL /* Translation Error encountered */
  56. #define SCHIZO_IOMMU_CTRL_LCKEN 0x0000000000800000UL /* Enable translation locking */
  57. #define SCHIZO_IOMMU_CTRL_LCKPTR 0x0000000000780000UL /* Translation lock pointer */
  58. #define SCHIZO_IOMMU_CTRL_TSBSZ 0x0000000000070000UL /* TSB Size */
  59. #define SCHIZO_IOMMU_TSBSZ_1K 0x0000000000000000UL /* TSB Table 1024 8-byte entries */
  60. #define SCHIZO_IOMMU_TSBSZ_2K 0x0000000000010000UL /* TSB Table 2048 8-byte entries */
  61. #define SCHIZO_IOMMU_TSBSZ_4K 0x0000000000020000UL /* TSB Table 4096 8-byte entries */
  62. #define SCHIZO_IOMMU_TSBSZ_8K 0x0000000000030000UL /* TSB Table 8192 8-byte entries */
  63. #define SCHIZO_IOMMU_TSBSZ_16K 0x0000000000040000UL /* TSB Table 16k 8-byte entries */
  64. #define SCHIZO_IOMMU_TSBSZ_32K 0x0000000000050000UL /* TSB Table 32k 8-byte entries */
  65. #define SCHIZO_IOMMU_TSBSZ_64K 0x0000000000060000UL /* TSB Table 64k 8-byte entries */
  66. #define SCHIZO_IOMMU_TSBSZ_128K 0x0000000000070000UL /* TSB Table 128k 8-byte entries */
  67. #define SCHIZO_IOMMU_CTRL_RESV2 0x000000000000fff8UL /* Reserved */
  68. #define SCHIZO_IOMMU_CTRL_TBWSZ 0x0000000000000004UL /* Assumed page size, 0=8k 1=64k */
  69. #define SCHIZO_IOMMU_CTRL_DENAB 0x0000000000000002UL /* Diagnostic mode enable */
  70. #define SCHIZO_IOMMU_CTRL_ENAB 0x0000000000000001UL /* IOMMU Enable */
  71. /* Schizo config space address format is nearly identical to
  72. * that of PSYCHO:
  73. *
  74. * 32 24 23 16 15 11 10 8 7 2 1 0
  75. * ---------------------------------------------------------
  76. * |0 0 0 0 0 0 0 0 0| bus | device | function | reg | 0 0 |
  77. * ---------------------------------------------------------
  78. */
  79. #define SCHIZO_CONFIG_BASE(PBM) ((PBM)->config_space)
  80. #define SCHIZO_CONFIG_ENCODE(BUS, DEVFN, REG) \
  81. (((unsigned long)(BUS) << 16) | \
  82. ((unsigned long)(DEVFN) << 8) | \
  83. ((unsigned long)(REG)))
  84. static void *schizo_pci_config_mkaddr(struct pci_pbm_info *pbm,
  85. unsigned char bus,
  86. unsigned int devfn,
  87. int where)
  88. {
  89. if (!pbm)
  90. return NULL;
  91. bus -= pbm->pci_first_busno;
  92. return (void *)
  93. (SCHIZO_CONFIG_BASE(pbm) |
  94. SCHIZO_CONFIG_ENCODE(bus, devfn, where));
  95. }
  96. /* Just make sure the bus number is in range. */
  97. static int schizo_out_of_range(struct pci_pbm_info *pbm,
  98. unsigned char bus,
  99. unsigned char devfn)
  100. {
  101. if (bus < pbm->pci_first_busno ||
  102. bus > pbm->pci_last_busno)
  103. return 1;
  104. return 0;
  105. }
  106. /* SCHIZO PCI configuration space accessors. */
  107. static int schizo_read_pci_cfg(struct pci_bus *bus_dev, unsigned int devfn,
  108. int where, int size, u32 *value)
  109. {
  110. struct pci_pbm_info *pbm = bus_dev->sysdata;
  111. unsigned char bus = bus_dev->number;
  112. u32 *addr;
  113. u16 tmp16;
  114. u8 tmp8;
  115. switch (size) {
  116. case 1:
  117. *value = 0xff;
  118. break;
  119. case 2:
  120. *value = 0xffff;
  121. break;
  122. case 4:
  123. *value = 0xffffffff;
  124. break;
  125. }
  126. addr = schizo_pci_config_mkaddr(pbm, bus, devfn, where);
  127. if (!addr)
  128. return PCIBIOS_SUCCESSFUL;
  129. if (schizo_out_of_range(pbm, bus, devfn))
  130. return PCIBIOS_SUCCESSFUL;
  131. switch (size) {
  132. case 1:
  133. pci_config_read8((u8 *)addr, &tmp8);
  134. *value = tmp8;
  135. break;
  136. case 2:
  137. if (where & 0x01) {
  138. printk("pci_read_config_word: misaligned reg [%x]\n",
  139. where);
  140. return PCIBIOS_SUCCESSFUL;
  141. }
  142. pci_config_read16((u16 *)addr, &tmp16);
  143. *value = tmp16;
  144. break;
  145. case 4:
  146. if (where & 0x03) {
  147. printk("pci_read_config_dword: misaligned reg [%x]\n",
  148. where);
  149. return PCIBIOS_SUCCESSFUL;
  150. }
  151. pci_config_read32(addr, value);
  152. break;
  153. }
  154. return PCIBIOS_SUCCESSFUL;
  155. }
  156. static int schizo_write_pci_cfg(struct pci_bus *bus_dev, unsigned int devfn,
  157. int where, int size, u32 value)
  158. {
  159. struct pci_pbm_info *pbm = bus_dev->sysdata;
  160. unsigned char bus = bus_dev->number;
  161. u32 *addr;
  162. addr = schizo_pci_config_mkaddr(pbm, bus, devfn, where);
  163. if (!addr)
  164. return PCIBIOS_SUCCESSFUL;
  165. if (schizo_out_of_range(pbm, bus, devfn))
  166. return PCIBIOS_SUCCESSFUL;
  167. switch (size) {
  168. case 1:
  169. pci_config_write8((u8 *)addr, value);
  170. break;
  171. case 2:
  172. if (where & 0x01) {
  173. printk("pci_write_config_word: misaligned reg [%x]\n",
  174. where);
  175. return PCIBIOS_SUCCESSFUL;
  176. }
  177. pci_config_write16((u16 *)addr, value);
  178. break;
  179. case 4:
  180. if (where & 0x03) {
  181. printk("pci_write_config_dword: misaligned reg [%x]\n",
  182. where);
  183. return PCIBIOS_SUCCESSFUL;
  184. }
  185. pci_config_write32(addr, value);
  186. }
  187. return PCIBIOS_SUCCESSFUL;
  188. }
  189. static struct pci_ops schizo_ops = {
  190. .read = schizo_read_pci_cfg,
  191. .write = schizo_write_pci_cfg,
  192. };
  193. /* SCHIZO error handling support. */
  194. enum schizo_error_type {
  195. UE_ERR, CE_ERR, PCI_ERR, SAFARI_ERR
  196. };
  197. static DEFINE_SPINLOCK(stc_buf_lock);
  198. static unsigned long stc_error_buf[128];
  199. static unsigned long stc_tag_buf[16];
  200. static unsigned long stc_line_buf[16];
  201. #define SCHIZO_UE_INO 0x30 /* Uncorrectable ECC error */
  202. #define SCHIZO_CE_INO 0x31 /* Correctable ECC error */
  203. #define SCHIZO_PCIERR_A_INO 0x32 /* PBM A PCI bus error */
  204. #define SCHIZO_PCIERR_B_INO 0x33 /* PBM B PCI bus error */
  205. #define SCHIZO_SERR_INO 0x34 /* Safari interface error */
  206. struct pci_pbm_info *pbm_for_ino(struct pci_controller_info *p, u32 ino)
  207. {
  208. ino &= IMAP_INO;
  209. if (p->pbm_A.ino_bitmap & (1UL << ino))
  210. return &p->pbm_A;
  211. if (p->pbm_B.ino_bitmap & (1UL << ino))
  212. return &p->pbm_B;
  213. printk("PCI%d: No ino_bitmap entry for ino[%x], bitmaps "
  214. "PBM_A[%016lx] PBM_B[%016lx]",
  215. p->index, ino,
  216. p->pbm_A.ino_bitmap,
  217. p->pbm_B.ino_bitmap);
  218. printk("PCI%d: Using PBM_A, report this problem immediately.\n",
  219. p->index);
  220. return &p->pbm_A;
  221. }
  222. #define SCHIZO_STC_ERR 0xb800UL /* --> 0xba00 */
  223. #define SCHIZO_STC_TAG 0xba00UL /* --> 0xba80 */
  224. #define SCHIZO_STC_LINE 0xbb00UL /* --> 0xbb80 */
  225. #define SCHIZO_STCERR_WRITE 0x2UL
  226. #define SCHIZO_STCERR_READ 0x1UL
  227. #define SCHIZO_STCTAG_PPN 0x3fffffff00000000UL
  228. #define SCHIZO_STCTAG_VPN 0x00000000ffffe000UL
  229. #define SCHIZO_STCTAG_VALID 0x8000000000000000UL
  230. #define SCHIZO_STCTAG_READ 0x4000000000000000UL
  231. #define SCHIZO_STCLINE_LINDX 0x0000000007800000UL
  232. #define SCHIZO_STCLINE_SPTR 0x000000000007e000UL
  233. #define SCHIZO_STCLINE_LADDR 0x0000000000001fc0UL
  234. #define SCHIZO_STCLINE_EPTR 0x000000000000003fUL
  235. #define SCHIZO_STCLINE_VALID 0x0000000000600000UL
  236. #define SCHIZO_STCLINE_FOFN 0x0000000000180000UL
  237. static void __schizo_check_stc_error_pbm(struct pci_pbm_info *pbm,
  238. enum schizo_error_type type)
  239. {
  240. struct pci_strbuf *strbuf = &pbm->stc;
  241. unsigned long regbase = pbm->pbm_regs;
  242. unsigned long err_base, tag_base, line_base;
  243. u64 control;
  244. int i;
  245. err_base = regbase + SCHIZO_STC_ERR;
  246. tag_base = regbase + SCHIZO_STC_TAG;
  247. line_base = regbase + SCHIZO_STC_LINE;
  248. spin_lock(&stc_buf_lock);
  249. /* This is __REALLY__ dangerous. When we put the
  250. * streaming buffer into diagnostic mode to probe
  251. * it's tags and error status, we _must_ clear all
  252. * of the line tag valid bits before re-enabling
  253. * the streaming buffer. If any dirty data lives
  254. * in the STC when we do this, we will end up
  255. * invalidating it before it has a chance to reach
  256. * main memory.
  257. */
  258. control = schizo_read(strbuf->strbuf_control);
  259. schizo_write(strbuf->strbuf_control,
  260. (control | SCHIZO_STRBUF_CTRL_DENAB));
  261. for (i = 0; i < 128; i++) {
  262. unsigned long val;
  263. val = schizo_read(err_base + (i * 8UL));
  264. schizo_write(err_base + (i * 8UL), 0UL);
  265. stc_error_buf[i] = val;
  266. }
  267. for (i = 0; i < 16; i++) {
  268. stc_tag_buf[i] = schizo_read(tag_base + (i * 8UL));
  269. stc_line_buf[i] = schizo_read(line_base + (i * 8UL));
  270. schizo_write(tag_base + (i * 8UL), 0UL);
  271. schizo_write(line_base + (i * 8UL), 0UL);
  272. }
  273. /* OK, state is logged, exit diagnostic mode. */
  274. schizo_write(strbuf->strbuf_control, control);
  275. for (i = 0; i < 16; i++) {
  276. int j, saw_error, first, last;
  277. saw_error = 0;
  278. first = i * 8;
  279. last = first + 8;
  280. for (j = first; j < last; j++) {
  281. unsigned long errval = stc_error_buf[j];
  282. if (errval != 0) {
  283. saw_error++;
  284. printk("%s: STC_ERR(%d)[wr(%d)rd(%d)]\n",
  285. pbm->name,
  286. j,
  287. (errval & SCHIZO_STCERR_WRITE) ? 1 : 0,
  288. (errval & SCHIZO_STCERR_READ) ? 1 : 0);
  289. }
  290. }
  291. if (saw_error != 0) {
  292. unsigned long tagval = stc_tag_buf[i];
  293. unsigned long lineval = stc_line_buf[i];
  294. printk("%s: STC_TAG(%d)[PA(%016lx)VA(%08lx)V(%d)R(%d)]\n",
  295. pbm->name,
  296. i,
  297. ((tagval & SCHIZO_STCTAG_PPN) >> 19UL),
  298. (tagval & SCHIZO_STCTAG_VPN),
  299. ((tagval & SCHIZO_STCTAG_VALID) ? 1 : 0),
  300. ((tagval & SCHIZO_STCTAG_READ) ? 1 : 0));
  301. /* XXX Should spit out per-bank error information... -DaveM */
  302. printk("%s: STC_LINE(%d)[LIDX(%lx)SP(%lx)LADDR(%lx)EP(%lx)"
  303. "V(%d)FOFN(%d)]\n",
  304. pbm->name,
  305. i,
  306. ((lineval & SCHIZO_STCLINE_LINDX) >> 23UL),
  307. ((lineval & SCHIZO_STCLINE_SPTR) >> 13UL),
  308. ((lineval & SCHIZO_STCLINE_LADDR) >> 6UL),
  309. ((lineval & SCHIZO_STCLINE_EPTR) >> 0UL),
  310. ((lineval & SCHIZO_STCLINE_VALID) ? 1 : 0),
  311. ((lineval & SCHIZO_STCLINE_FOFN) ? 1 : 0));
  312. }
  313. }
  314. spin_unlock(&stc_buf_lock);
  315. }
  316. /* IOMMU is per-PBM in Schizo, so interrogate both for anonymous
  317. * controller level errors.
  318. */
  319. #define SCHIZO_IOMMU_TAG 0xa580UL
  320. #define SCHIZO_IOMMU_DATA 0xa600UL
  321. #define SCHIZO_IOMMU_TAG_CTXT 0x0000001ffe000000UL
  322. #define SCHIZO_IOMMU_TAG_ERRSTS 0x0000000001800000UL
  323. #define SCHIZO_IOMMU_TAG_ERR 0x0000000000400000UL
  324. #define SCHIZO_IOMMU_TAG_WRITE 0x0000000000200000UL
  325. #define SCHIZO_IOMMU_TAG_STREAM 0x0000000000100000UL
  326. #define SCHIZO_IOMMU_TAG_SIZE 0x0000000000080000UL
  327. #define SCHIZO_IOMMU_TAG_VPAGE 0x000000000007ffffUL
  328. #define SCHIZO_IOMMU_DATA_VALID 0x0000000100000000UL
  329. #define SCHIZO_IOMMU_DATA_CACHE 0x0000000040000000UL
  330. #define SCHIZO_IOMMU_DATA_PPAGE 0x000000003fffffffUL
  331. static void schizo_check_iommu_error_pbm(struct pci_pbm_info *pbm,
  332. enum schizo_error_type type)
  333. {
  334. struct pci_iommu *iommu = pbm->iommu;
  335. unsigned long iommu_tag[16];
  336. unsigned long iommu_data[16];
  337. unsigned long flags;
  338. u64 control;
  339. int i;
  340. spin_lock_irqsave(&iommu->lock, flags);
  341. control = schizo_read(iommu->iommu_control);
  342. if (control & SCHIZO_IOMMU_CTRL_XLTEERR) {
  343. unsigned long base;
  344. char *type_string;
  345. /* Clear the error encountered bit. */
  346. control &= ~SCHIZO_IOMMU_CTRL_XLTEERR;
  347. schizo_write(iommu->iommu_control, control);
  348. switch((control & SCHIZO_IOMMU_CTRL_XLTESTAT) >> 25UL) {
  349. case 0:
  350. type_string = "Protection Error";
  351. break;
  352. case 1:
  353. type_string = "Invalid Error";
  354. break;
  355. case 2:
  356. type_string = "TimeOut Error";
  357. break;
  358. case 3:
  359. default:
  360. type_string = "ECC Error";
  361. break;
  362. };
  363. printk("%s: IOMMU Error, type[%s]\n",
  364. pbm->name, type_string);
  365. /* Put the IOMMU into diagnostic mode and probe
  366. * it's TLB for entries with error status.
  367. *
  368. * It is very possible for another DVMA to occur
  369. * while we do this probe, and corrupt the system
  370. * further. But we are so screwed at this point
  371. * that we are likely to crash hard anyways, so
  372. * get as much diagnostic information to the
  373. * console as we can.
  374. */
  375. schizo_write(iommu->iommu_control,
  376. control | SCHIZO_IOMMU_CTRL_DENAB);
  377. base = pbm->pbm_regs;
  378. for (i = 0; i < 16; i++) {
  379. iommu_tag[i] =
  380. schizo_read(base + SCHIZO_IOMMU_TAG + (i * 8UL));
  381. iommu_data[i] =
  382. schizo_read(base + SCHIZO_IOMMU_DATA + (i * 8UL));
  383. /* Now clear out the entry. */
  384. schizo_write(base + SCHIZO_IOMMU_TAG + (i * 8UL), 0);
  385. schizo_write(base + SCHIZO_IOMMU_DATA + (i * 8UL), 0);
  386. }
  387. /* Leave diagnostic mode. */
  388. schizo_write(iommu->iommu_control, control);
  389. for (i = 0; i < 16; i++) {
  390. unsigned long tag, data;
  391. tag = iommu_tag[i];
  392. if (!(tag & SCHIZO_IOMMU_TAG_ERR))
  393. continue;
  394. data = iommu_data[i];
  395. switch((tag & SCHIZO_IOMMU_TAG_ERRSTS) >> 23UL) {
  396. case 0:
  397. type_string = "Protection Error";
  398. break;
  399. case 1:
  400. type_string = "Invalid Error";
  401. break;
  402. case 2:
  403. type_string = "TimeOut Error";
  404. break;
  405. case 3:
  406. default:
  407. type_string = "ECC Error";
  408. break;
  409. };
  410. printk("%s: IOMMU TAG(%d)[error(%s) ctx(%x) wr(%d) str(%d) "
  411. "sz(%dK) vpg(%08lx)]\n",
  412. pbm->name, i, type_string,
  413. (int)((tag & SCHIZO_IOMMU_TAG_CTXT) >> 25UL),
  414. ((tag & SCHIZO_IOMMU_TAG_WRITE) ? 1 : 0),
  415. ((tag & SCHIZO_IOMMU_TAG_STREAM) ? 1 : 0),
  416. ((tag & SCHIZO_IOMMU_TAG_SIZE) ? 64 : 8),
  417. (tag & SCHIZO_IOMMU_TAG_VPAGE) << IOMMU_PAGE_SHIFT);
  418. printk("%s: IOMMU DATA(%d)[valid(%d) cache(%d) ppg(%016lx)]\n",
  419. pbm->name, i,
  420. ((data & SCHIZO_IOMMU_DATA_VALID) ? 1 : 0),
  421. ((data & SCHIZO_IOMMU_DATA_CACHE) ? 1 : 0),
  422. (data & SCHIZO_IOMMU_DATA_PPAGE) << IOMMU_PAGE_SHIFT);
  423. }
  424. }
  425. if (pbm->stc.strbuf_enabled)
  426. __schizo_check_stc_error_pbm(pbm, type);
  427. spin_unlock_irqrestore(&iommu->lock, flags);
  428. }
  429. static void schizo_check_iommu_error(struct pci_controller_info *p,
  430. enum schizo_error_type type)
  431. {
  432. schizo_check_iommu_error_pbm(&p->pbm_A, type);
  433. schizo_check_iommu_error_pbm(&p->pbm_B, type);
  434. }
  435. /* Uncorrectable ECC error status gathering. */
  436. #define SCHIZO_UE_AFSR 0x10030UL
  437. #define SCHIZO_UE_AFAR 0x10038UL
  438. #define SCHIZO_UEAFSR_PPIO 0x8000000000000000UL /* Safari */
  439. #define SCHIZO_UEAFSR_PDRD 0x4000000000000000UL /* Safari/Tomatillo */
  440. #define SCHIZO_UEAFSR_PDWR 0x2000000000000000UL /* Safari */
  441. #define SCHIZO_UEAFSR_SPIO 0x1000000000000000UL /* Safari */
  442. #define SCHIZO_UEAFSR_SDMA 0x0800000000000000UL /* Safari/Tomatillo */
  443. #define SCHIZO_UEAFSR_ERRPNDG 0x0300000000000000UL /* Safari */
  444. #define SCHIZO_UEAFSR_BMSK 0x000003ff00000000UL /* Safari */
  445. #define SCHIZO_UEAFSR_QOFF 0x00000000c0000000UL /* Safari/Tomatillo */
  446. #define SCHIZO_UEAFSR_AID 0x000000001f000000UL /* Safari/Tomatillo */
  447. #define SCHIZO_UEAFSR_PARTIAL 0x0000000000800000UL /* Safari */
  448. #define SCHIZO_UEAFSR_OWNEDIN 0x0000000000400000UL /* Safari */
  449. #define SCHIZO_UEAFSR_MTAGSYND 0x00000000000f0000UL /* Safari */
  450. #define SCHIZO_UEAFSR_MTAG 0x000000000000e000UL /* Safari */
  451. #define SCHIZO_UEAFSR_ECCSYND 0x00000000000001ffUL /* Safari */
  452. static irqreturn_t schizo_ue_intr(int irq, void *dev_id)
  453. {
  454. struct pci_controller_info *p = dev_id;
  455. unsigned long afsr_reg = p->pbm_B.controller_regs + SCHIZO_UE_AFSR;
  456. unsigned long afar_reg = p->pbm_B.controller_regs + SCHIZO_UE_AFAR;
  457. unsigned long afsr, afar, error_bits;
  458. int reported, limit;
  459. /* Latch uncorrectable error status. */
  460. afar = schizo_read(afar_reg);
  461. /* If either of the error pending bits are set in the
  462. * AFSR, the error status is being actively updated by
  463. * the hardware and we must re-read to get a clean value.
  464. */
  465. limit = 1000;
  466. do {
  467. afsr = schizo_read(afsr_reg);
  468. } while ((afsr & SCHIZO_UEAFSR_ERRPNDG) != 0 && --limit);
  469. /* Clear the primary/secondary error status bits. */
  470. error_bits = afsr &
  471. (SCHIZO_UEAFSR_PPIO | SCHIZO_UEAFSR_PDRD | SCHIZO_UEAFSR_PDWR |
  472. SCHIZO_UEAFSR_SPIO | SCHIZO_UEAFSR_SDMA);
  473. if (!error_bits)
  474. return IRQ_NONE;
  475. schizo_write(afsr_reg, error_bits);
  476. /* Log the error. */
  477. printk("PCI%d: Uncorrectable Error, primary error type[%s]\n",
  478. p->index,
  479. (((error_bits & SCHIZO_UEAFSR_PPIO) ?
  480. "PIO" :
  481. ((error_bits & SCHIZO_UEAFSR_PDRD) ?
  482. "DMA Read" :
  483. ((error_bits & SCHIZO_UEAFSR_PDWR) ?
  484. "DMA Write" : "???")))));
  485. printk("PCI%d: bytemask[%04lx] qword_offset[%lx] SAFARI_AID[%02lx]\n",
  486. p->index,
  487. (afsr & SCHIZO_UEAFSR_BMSK) >> 32UL,
  488. (afsr & SCHIZO_UEAFSR_QOFF) >> 30UL,
  489. (afsr & SCHIZO_UEAFSR_AID) >> 24UL);
  490. printk("PCI%d: partial[%d] owned_in[%d] mtag[%lx] mtag_synd[%lx] ecc_sync[%lx]\n",
  491. p->index,
  492. (afsr & SCHIZO_UEAFSR_PARTIAL) ? 1 : 0,
  493. (afsr & SCHIZO_UEAFSR_OWNEDIN) ? 1 : 0,
  494. (afsr & SCHIZO_UEAFSR_MTAG) >> 13UL,
  495. (afsr & SCHIZO_UEAFSR_MTAGSYND) >> 16UL,
  496. (afsr & SCHIZO_UEAFSR_ECCSYND) >> 0UL);
  497. printk("PCI%d: UE AFAR [%016lx]\n", p->index, afar);
  498. printk("PCI%d: UE Secondary errors [", p->index);
  499. reported = 0;
  500. if (afsr & SCHIZO_UEAFSR_SPIO) {
  501. reported++;
  502. printk("(PIO)");
  503. }
  504. if (afsr & SCHIZO_UEAFSR_SDMA) {
  505. reported++;
  506. printk("(DMA)");
  507. }
  508. if (!reported)
  509. printk("(none)");
  510. printk("]\n");
  511. /* Interrogate IOMMU for error status. */
  512. schizo_check_iommu_error(p, UE_ERR);
  513. return IRQ_HANDLED;
  514. }
  515. #define SCHIZO_CE_AFSR 0x10040UL
  516. #define SCHIZO_CE_AFAR 0x10048UL
  517. #define SCHIZO_CEAFSR_PPIO 0x8000000000000000UL
  518. #define SCHIZO_CEAFSR_PDRD 0x4000000000000000UL
  519. #define SCHIZO_CEAFSR_PDWR 0x2000000000000000UL
  520. #define SCHIZO_CEAFSR_SPIO 0x1000000000000000UL
  521. #define SCHIZO_CEAFSR_SDMA 0x0800000000000000UL
  522. #define SCHIZO_CEAFSR_ERRPNDG 0x0300000000000000UL
  523. #define SCHIZO_CEAFSR_BMSK 0x000003ff00000000UL
  524. #define SCHIZO_CEAFSR_QOFF 0x00000000c0000000UL
  525. #define SCHIZO_CEAFSR_AID 0x000000001f000000UL
  526. #define SCHIZO_CEAFSR_PARTIAL 0x0000000000800000UL
  527. #define SCHIZO_CEAFSR_OWNEDIN 0x0000000000400000UL
  528. #define SCHIZO_CEAFSR_MTAGSYND 0x00000000000f0000UL
  529. #define SCHIZO_CEAFSR_MTAG 0x000000000000e000UL
  530. #define SCHIZO_CEAFSR_ECCSYND 0x00000000000001ffUL
  531. static irqreturn_t schizo_ce_intr(int irq, void *dev_id)
  532. {
  533. struct pci_controller_info *p = dev_id;
  534. unsigned long afsr_reg = p->pbm_B.controller_regs + SCHIZO_CE_AFSR;
  535. unsigned long afar_reg = p->pbm_B.controller_regs + SCHIZO_CE_AFAR;
  536. unsigned long afsr, afar, error_bits;
  537. int reported, limit;
  538. /* Latch error status. */
  539. afar = schizo_read(afar_reg);
  540. /* If either of the error pending bits are set in the
  541. * AFSR, the error status is being actively updated by
  542. * the hardware and we must re-read to get a clean value.
  543. */
  544. limit = 1000;
  545. do {
  546. afsr = schizo_read(afsr_reg);
  547. } while ((afsr & SCHIZO_UEAFSR_ERRPNDG) != 0 && --limit);
  548. /* Clear primary/secondary error status bits. */
  549. error_bits = afsr &
  550. (SCHIZO_CEAFSR_PPIO | SCHIZO_CEAFSR_PDRD | SCHIZO_CEAFSR_PDWR |
  551. SCHIZO_CEAFSR_SPIO | SCHIZO_CEAFSR_SDMA);
  552. if (!error_bits)
  553. return IRQ_NONE;
  554. schizo_write(afsr_reg, error_bits);
  555. /* Log the error. */
  556. printk("PCI%d: Correctable Error, primary error type[%s]\n",
  557. p->index,
  558. (((error_bits & SCHIZO_CEAFSR_PPIO) ?
  559. "PIO" :
  560. ((error_bits & SCHIZO_CEAFSR_PDRD) ?
  561. "DMA Read" :
  562. ((error_bits & SCHIZO_CEAFSR_PDWR) ?
  563. "DMA Write" : "???")))));
  564. /* XXX Use syndrome and afar to print out module string just like
  565. * XXX UDB CE trap handler does... -DaveM
  566. */
  567. printk("PCI%d: bytemask[%04lx] qword_offset[%lx] SAFARI_AID[%02lx]\n",
  568. p->index,
  569. (afsr & SCHIZO_UEAFSR_BMSK) >> 32UL,
  570. (afsr & SCHIZO_UEAFSR_QOFF) >> 30UL,
  571. (afsr & SCHIZO_UEAFSR_AID) >> 24UL);
  572. printk("PCI%d: partial[%d] owned_in[%d] mtag[%lx] mtag_synd[%lx] ecc_sync[%lx]\n",
  573. p->index,
  574. (afsr & SCHIZO_UEAFSR_PARTIAL) ? 1 : 0,
  575. (afsr & SCHIZO_UEAFSR_OWNEDIN) ? 1 : 0,
  576. (afsr & SCHIZO_UEAFSR_MTAG) >> 13UL,
  577. (afsr & SCHIZO_UEAFSR_MTAGSYND) >> 16UL,
  578. (afsr & SCHIZO_UEAFSR_ECCSYND) >> 0UL);
  579. printk("PCI%d: CE AFAR [%016lx]\n", p->index, afar);
  580. printk("PCI%d: CE Secondary errors [", p->index);
  581. reported = 0;
  582. if (afsr & SCHIZO_CEAFSR_SPIO) {
  583. reported++;
  584. printk("(PIO)");
  585. }
  586. if (afsr & SCHIZO_CEAFSR_SDMA) {
  587. reported++;
  588. printk("(DMA)");
  589. }
  590. if (!reported)
  591. printk("(none)");
  592. printk("]\n");
  593. return IRQ_HANDLED;
  594. }
  595. #define SCHIZO_PCI_AFSR 0x2010UL
  596. #define SCHIZO_PCI_AFAR 0x2018UL
  597. #define SCHIZO_PCIAFSR_PMA 0x8000000000000000UL /* Schizo/Tomatillo */
  598. #define SCHIZO_PCIAFSR_PTA 0x4000000000000000UL /* Schizo/Tomatillo */
  599. #define SCHIZO_PCIAFSR_PRTRY 0x2000000000000000UL /* Schizo/Tomatillo */
  600. #define SCHIZO_PCIAFSR_PPERR 0x1000000000000000UL /* Schizo/Tomatillo */
  601. #define SCHIZO_PCIAFSR_PTTO 0x0800000000000000UL /* Schizo/Tomatillo */
  602. #define SCHIZO_PCIAFSR_PUNUS 0x0400000000000000UL /* Schizo */
  603. #define SCHIZO_PCIAFSR_SMA 0x0200000000000000UL /* Schizo/Tomatillo */
  604. #define SCHIZO_PCIAFSR_STA 0x0100000000000000UL /* Schizo/Tomatillo */
  605. #define SCHIZO_PCIAFSR_SRTRY 0x0080000000000000UL /* Schizo/Tomatillo */
  606. #define SCHIZO_PCIAFSR_SPERR 0x0040000000000000UL /* Schizo/Tomatillo */
  607. #define SCHIZO_PCIAFSR_STTO 0x0020000000000000UL /* Schizo/Tomatillo */
  608. #define SCHIZO_PCIAFSR_SUNUS 0x0010000000000000UL /* Schizo */
  609. #define SCHIZO_PCIAFSR_BMSK 0x000003ff00000000UL /* Schizo/Tomatillo */
  610. #define SCHIZO_PCIAFSR_BLK 0x0000000080000000UL /* Schizo/Tomatillo */
  611. #define SCHIZO_PCIAFSR_CFG 0x0000000040000000UL /* Schizo/Tomatillo */
  612. #define SCHIZO_PCIAFSR_MEM 0x0000000020000000UL /* Schizo/Tomatillo */
  613. #define SCHIZO_PCIAFSR_IO 0x0000000010000000UL /* Schizo/Tomatillo */
  614. #define SCHIZO_PCI_CTRL (0x2000UL)
  615. #define SCHIZO_PCICTRL_BUS_UNUS (1UL << 63UL) /* Safari */
  616. #define SCHIZO_PCICTRL_DTO_INT (1UL << 61UL) /* Tomatillo */
  617. #define SCHIZO_PCICTRL_ARB_PRIO (0x1ff << 52UL) /* Tomatillo */
  618. #define SCHIZO_PCICTRL_ESLCK (1UL << 51UL) /* Safari */
  619. #define SCHIZO_PCICTRL_ERRSLOT (7UL << 48UL) /* Safari */
  620. #define SCHIZO_PCICTRL_TTO_ERR (1UL << 38UL) /* Safari/Tomatillo */
  621. #define SCHIZO_PCICTRL_RTRY_ERR (1UL << 37UL) /* Safari/Tomatillo */
  622. #define SCHIZO_PCICTRL_DTO_ERR (1UL << 36UL) /* Safari/Tomatillo */
  623. #define SCHIZO_PCICTRL_SBH_ERR (1UL << 35UL) /* Safari */
  624. #define SCHIZO_PCICTRL_SERR (1UL << 34UL) /* Safari/Tomatillo */
  625. #define SCHIZO_PCICTRL_PCISPD (1UL << 33UL) /* Safari */
  626. #define SCHIZO_PCICTRL_MRM_PREF (1UL << 30UL) /* Tomatillo */
  627. #define SCHIZO_PCICTRL_RDO_PREF (1UL << 29UL) /* Tomatillo */
  628. #define SCHIZO_PCICTRL_RDL_PREF (1UL << 28UL) /* Tomatillo */
  629. #define SCHIZO_PCICTRL_PTO (3UL << 24UL) /* Safari/Tomatillo */
  630. #define SCHIZO_PCICTRL_PTO_SHIFT 24UL
  631. #define SCHIZO_PCICTRL_TRWSW (7UL << 21UL) /* Tomatillo */
  632. #define SCHIZO_PCICTRL_F_TGT_A (1UL << 20UL) /* Tomatillo */
  633. #define SCHIZO_PCICTRL_S_DTO_INT (1UL << 19UL) /* Safari */
  634. #define SCHIZO_PCICTRL_F_TGT_RT (1UL << 19UL) /* Tomatillo */
  635. #define SCHIZO_PCICTRL_SBH_INT (1UL << 18UL) /* Safari */
  636. #define SCHIZO_PCICTRL_T_DTO_INT (1UL << 18UL) /* Tomatillo */
  637. #define SCHIZO_PCICTRL_EEN (1UL << 17UL) /* Safari/Tomatillo */
  638. #define SCHIZO_PCICTRL_PARK (1UL << 16UL) /* Safari/Tomatillo */
  639. #define SCHIZO_PCICTRL_PCIRST (1UL << 8UL) /* Safari */
  640. #define SCHIZO_PCICTRL_ARB_S (0x3fUL << 0UL) /* Safari */
  641. #define SCHIZO_PCICTRL_ARB_T (0xffUL << 0UL) /* Tomatillo */
  642. static irqreturn_t schizo_pcierr_intr_other(struct pci_pbm_info *pbm)
  643. {
  644. unsigned long csr_reg, csr, csr_error_bits;
  645. irqreturn_t ret = IRQ_NONE;
  646. u16 stat;
  647. csr_reg = pbm->pbm_regs + SCHIZO_PCI_CTRL;
  648. csr = schizo_read(csr_reg);
  649. csr_error_bits =
  650. csr & (SCHIZO_PCICTRL_BUS_UNUS |
  651. SCHIZO_PCICTRL_TTO_ERR |
  652. SCHIZO_PCICTRL_RTRY_ERR |
  653. SCHIZO_PCICTRL_DTO_ERR |
  654. SCHIZO_PCICTRL_SBH_ERR |
  655. SCHIZO_PCICTRL_SERR);
  656. if (csr_error_bits) {
  657. /* Clear the errors. */
  658. schizo_write(csr_reg, csr);
  659. /* Log 'em. */
  660. if (csr_error_bits & SCHIZO_PCICTRL_BUS_UNUS)
  661. printk("%s: Bus unusable error asserted.\n",
  662. pbm->name);
  663. if (csr_error_bits & SCHIZO_PCICTRL_TTO_ERR)
  664. printk("%s: PCI TRDY# timeout error asserted.\n",
  665. pbm->name);
  666. if (csr_error_bits & SCHIZO_PCICTRL_RTRY_ERR)
  667. printk("%s: PCI excessive retry error asserted.\n",
  668. pbm->name);
  669. if (csr_error_bits & SCHIZO_PCICTRL_DTO_ERR)
  670. printk("%s: PCI discard timeout error asserted.\n",
  671. pbm->name);
  672. if (csr_error_bits & SCHIZO_PCICTRL_SBH_ERR)
  673. printk("%s: PCI streaming byte hole error asserted.\n",
  674. pbm->name);
  675. if (csr_error_bits & SCHIZO_PCICTRL_SERR)
  676. printk("%s: PCI SERR signal asserted.\n",
  677. pbm->name);
  678. ret = IRQ_HANDLED;
  679. }
  680. pci_read_config_word(pbm->pci_bus->self, PCI_STATUS, &stat);
  681. if (stat & (PCI_STATUS_PARITY |
  682. PCI_STATUS_SIG_TARGET_ABORT |
  683. PCI_STATUS_REC_TARGET_ABORT |
  684. PCI_STATUS_REC_MASTER_ABORT |
  685. PCI_STATUS_SIG_SYSTEM_ERROR)) {
  686. printk("%s: PCI bus error, PCI_STATUS[%04x]\n",
  687. pbm->name, stat);
  688. pci_write_config_word(pbm->pci_bus->self, PCI_STATUS, 0xffff);
  689. ret = IRQ_HANDLED;
  690. }
  691. return ret;
  692. }
  693. static irqreturn_t schizo_pcierr_intr(int irq, void *dev_id)
  694. {
  695. struct pci_pbm_info *pbm = dev_id;
  696. struct pci_controller_info *p = pbm->parent;
  697. unsigned long afsr_reg, afar_reg, base;
  698. unsigned long afsr, afar, error_bits;
  699. int reported;
  700. base = pbm->pbm_regs;
  701. afsr_reg = base + SCHIZO_PCI_AFSR;
  702. afar_reg = base + SCHIZO_PCI_AFAR;
  703. /* Latch error status. */
  704. afar = schizo_read(afar_reg);
  705. afsr = schizo_read(afsr_reg);
  706. /* Clear primary/secondary error status bits. */
  707. error_bits = afsr &
  708. (SCHIZO_PCIAFSR_PMA | SCHIZO_PCIAFSR_PTA |
  709. SCHIZO_PCIAFSR_PRTRY | SCHIZO_PCIAFSR_PPERR |
  710. SCHIZO_PCIAFSR_PTTO | SCHIZO_PCIAFSR_PUNUS |
  711. SCHIZO_PCIAFSR_SMA | SCHIZO_PCIAFSR_STA |
  712. SCHIZO_PCIAFSR_SRTRY | SCHIZO_PCIAFSR_SPERR |
  713. SCHIZO_PCIAFSR_STTO | SCHIZO_PCIAFSR_SUNUS);
  714. if (!error_bits)
  715. return schizo_pcierr_intr_other(pbm);
  716. schizo_write(afsr_reg, error_bits);
  717. /* Log the error. */
  718. printk("%s: PCI Error, primary error type[%s]\n",
  719. pbm->name,
  720. (((error_bits & SCHIZO_PCIAFSR_PMA) ?
  721. "Master Abort" :
  722. ((error_bits & SCHIZO_PCIAFSR_PTA) ?
  723. "Target Abort" :
  724. ((error_bits & SCHIZO_PCIAFSR_PRTRY) ?
  725. "Excessive Retries" :
  726. ((error_bits & SCHIZO_PCIAFSR_PPERR) ?
  727. "Parity Error" :
  728. ((error_bits & SCHIZO_PCIAFSR_PTTO) ?
  729. "Timeout" :
  730. ((error_bits & SCHIZO_PCIAFSR_PUNUS) ?
  731. "Bus Unusable" : "???"))))))));
  732. printk("%s: bytemask[%04lx] was_block(%d) space(%s)\n",
  733. pbm->name,
  734. (afsr & SCHIZO_PCIAFSR_BMSK) >> 32UL,
  735. (afsr & SCHIZO_PCIAFSR_BLK) ? 1 : 0,
  736. ((afsr & SCHIZO_PCIAFSR_CFG) ?
  737. "Config" :
  738. ((afsr & SCHIZO_PCIAFSR_MEM) ?
  739. "Memory" :
  740. ((afsr & SCHIZO_PCIAFSR_IO) ?
  741. "I/O" : "???"))));
  742. printk("%s: PCI AFAR [%016lx]\n",
  743. pbm->name, afar);
  744. printk("%s: PCI Secondary errors [",
  745. pbm->name);
  746. reported = 0;
  747. if (afsr & SCHIZO_PCIAFSR_SMA) {
  748. reported++;
  749. printk("(Master Abort)");
  750. }
  751. if (afsr & SCHIZO_PCIAFSR_STA) {
  752. reported++;
  753. printk("(Target Abort)");
  754. }
  755. if (afsr & SCHIZO_PCIAFSR_SRTRY) {
  756. reported++;
  757. printk("(Excessive Retries)");
  758. }
  759. if (afsr & SCHIZO_PCIAFSR_SPERR) {
  760. reported++;
  761. printk("(Parity Error)");
  762. }
  763. if (afsr & SCHIZO_PCIAFSR_STTO) {
  764. reported++;
  765. printk("(Timeout)");
  766. }
  767. if (afsr & SCHIZO_PCIAFSR_SUNUS) {
  768. reported++;
  769. printk("(Bus Unusable)");
  770. }
  771. if (!reported)
  772. printk("(none)");
  773. printk("]\n");
  774. /* For the error types shown, scan PBM's PCI bus for devices
  775. * which have logged that error type.
  776. */
  777. /* If we see a Target Abort, this could be the result of an
  778. * IOMMU translation error of some sort. It is extremely
  779. * useful to log this information as usually it indicates
  780. * a bug in the IOMMU support code or a PCI device driver.
  781. */
  782. if (error_bits & (SCHIZO_PCIAFSR_PTA | SCHIZO_PCIAFSR_STA)) {
  783. schizo_check_iommu_error(p, PCI_ERR);
  784. pci_scan_for_target_abort(p, pbm, pbm->pci_bus);
  785. }
  786. if (error_bits & (SCHIZO_PCIAFSR_PMA | SCHIZO_PCIAFSR_SMA))
  787. pci_scan_for_master_abort(p, pbm, pbm->pci_bus);
  788. /* For excessive retries, PSYCHO/PBM will abort the device
  789. * and there is no way to specifically check for excessive
  790. * retries in the config space status registers. So what
  791. * we hope is that we'll catch it via the master/target
  792. * abort events.
  793. */
  794. if (error_bits & (SCHIZO_PCIAFSR_PPERR | SCHIZO_PCIAFSR_SPERR))
  795. pci_scan_for_parity_error(p, pbm, pbm->pci_bus);
  796. return IRQ_HANDLED;
  797. }
  798. #define SCHIZO_SAFARI_ERRLOG 0x10018UL
  799. #define SAFARI_ERRLOG_ERROUT 0x8000000000000000UL
  800. #define BUS_ERROR_BADCMD 0x4000000000000000UL /* Schizo/Tomatillo */
  801. #define BUS_ERROR_SSMDIS 0x2000000000000000UL /* Safari */
  802. #define BUS_ERROR_BADMA 0x1000000000000000UL /* Safari */
  803. #define BUS_ERROR_BADMB 0x0800000000000000UL /* Safari */
  804. #define BUS_ERROR_BADMC 0x0400000000000000UL /* Safari */
  805. #define BUS_ERROR_SNOOP_GR 0x0000000000200000UL /* Tomatillo */
  806. #define BUS_ERROR_SNOOP_PCI 0x0000000000100000UL /* Tomatillo */
  807. #define BUS_ERROR_SNOOP_RD 0x0000000000080000UL /* Tomatillo */
  808. #define BUS_ERROR_SNOOP_RDS 0x0000000000020000UL /* Tomatillo */
  809. #define BUS_ERROR_SNOOP_RDSA 0x0000000000010000UL /* Tomatillo */
  810. #define BUS_ERROR_SNOOP_OWN 0x0000000000008000UL /* Tomatillo */
  811. #define BUS_ERROR_SNOOP_RDO 0x0000000000004000UL /* Tomatillo */
  812. #define BUS_ERROR_CPU1PS 0x0000000000002000UL /* Safari */
  813. #define BUS_ERROR_WDATA_PERR 0x0000000000002000UL /* Tomatillo */
  814. #define BUS_ERROR_CPU1PB 0x0000000000001000UL /* Safari */
  815. #define BUS_ERROR_CTRL_PERR 0x0000000000001000UL /* Tomatillo */
  816. #define BUS_ERROR_CPU0PS 0x0000000000000800UL /* Safari */
  817. #define BUS_ERROR_SNOOP_ERR 0x0000000000000800UL /* Tomatillo */
  818. #define BUS_ERROR_CPU0PB 0x0000000000000400UL /* Safari */
  819. #define BUS_ERROR_JBUS_ILL_B 0x0000000000000400UL /* Tomatillo */
  820. #define BUS_ERROR_CIQTO 0x0000000000000200UL /* Safari */
  821. #define BUS_ERROR_LPQTO 0x0000000000000100UL /* Safari */
  822. #define BUS_ERROR_JBUS_ILL_C 0x0000000000000100UL /* Tomatillo */
  823. #define BUS_ERROR_SFPQTO 0x0000000000000080UL /* Safari */
  824. #define BUS_ERROR_UFPQTO 0x0000000000000040UL /* Safari */
  825. #define BUS_ERROR_RD_PERR 0x0000000000000040UL /* Tomatillo */
  826. #define BUS_ERROR_APERR 0x0000000000000020UL /* Safari/Tomatillo */
  827. #define BUS_ERROR_UNMAP 0x0000000000000010UL /* Safari/Tomatillo */
  828. #define BUS_ERROR_BUSERR 0x0000000000000004UL /* Safari/Tomatillo */
  829. #define BUS_ERROR_TIMEOUT 0x0000000000000002UL /* Safari/Tomatillo */
  830. #define BUS_ERROR_ILL 0x0000000000000001UL /* Safari */
  831. /* We only expect UNMAP errors here. The rest of the Safari errors
  832. * are marked fatal and thus cause a system reset.
  833. */
  834. static irqreturn_t schizo_safarierr_intr(int irq, void *dev_id)
  835. {
  836. struct pci_controller_info *p = dev_id;
  837. u64 errlog;
  838. errlog = schizo_read(p->pbm_B.controller_regs + SCHIZO_SAFARI_ERRLOG);
  839. schizo_write(p->pbm_B.controller_regs + SCHIZO_SAFARI_ERRLOG,
  840. errlog & ~(SAFARI_ERRLOG_ERROUT));
  841. if (!(errlog & BUS_ERROR_UNMAP)) {
  842. printk("PCI%d: Unexpected Safari/JBUS error interrupt, errlog[%016lx]\n",
  843. p->index, errlog);
  844. return IRQ_HANDLED;
  845. }
  846. printk("PCI%d: Safari/JBUS interrupt, UNMAPPED error, interrogating IOMMUs.\n",
  847. p->index);
  848. schizo_check_iommu_error(p, SAFARI_ERR);
  849. return IRQ_HANDLED;
  850. }
  851. /* Nearly identical to PSYCHO equivalents... */
  852. #define SCHIZO_ECC_CTRL 0x10020UL
  853. #define SCHIZO_ECCCTRL_EE 0x8000000000000000UL /* Enable ECC Checking */
  854. #define SCHIZO_ECCCTRL_UE 0x4000000000000000UL /* Enable UE Interrupts */
  855. #define SCHIZO_ECCCTRL_CE 0x2000000000000000UL /* Enable CE INterrupts */
  856. #define SCHIZO_SAFARI_ERRCTRL 0x10008UL
  857. #define SCHIZO_SAFERRCTRL_EN 0x8000000000000000UL
  858. #define SCHIZO_SAFARI_IRQCTRL 0x10010UL
  859. #define SCHIZO_SAFIRQCTRL_EN 0x8000000000000000UL
  860. /* How the Tomatillo IRQs are routed around is pure guesswork here.
  861. *
  862. * All the Tomatillo devices I see in prtconf dumps seem to have only
  863. * a single PCI bus unit attached to it. It would seem they are seperate
  864. * devices because their PortID (ie. JBUS ID) values are all different
  865. * and thus the registers are mapped to totally different locations.
  866. *
  867. * However, two Tomatillo's look "similar" in that the only difference
  868. * in their PortID is the lowest bit.
  869. *
  870. * So if we were to ignore this lower bit, it certainly looks like two
  871. * PCI bus units of the same Tomatillo. I still have not really
  872. * figured this out...
  873. */
  874. static void tomatillo_register_error_handlers(struct pci_controller_info *p)
  875. {
  876. struct pci_pbm_info *pbm;
  877. struct of_device *op;
  878. u64 tmp, err_mask, err_no_mask;
  879. /* Tomatillo IRQ property layout is:
  880. * 0: PCIERR
  881. * 1: UE ERR
  882. * 2: CE ERR
  883. * 3: SERR
  884. * 4: POWER FAIL?
  885. */
  886. pbm = pbm_for_ino(p, SCHIZO_UE_INO);
  887. op = of_find_device_by_node(pbm->prom_node);
  888. if (op)
  889. request_irq(op->irqs[1], schizo_ue_intr, IRQF_SHARED,
  890. "TOMATILLO_UE", p);
  891. pbm = pbm_for_ino(p, SCHIZO_CE_INO);
  892. op = of_find_device_by_node(pbm->prom_node);
  893. if (op)
  894. request_irq(op->irqs[2], schizo_ce_intr, IRQF_SHARED,
  895. "TOMATILLO CE", p);
  896. pbm = pbm_for_ino(p, SCHIZO_PCIERR_A_INO);
  897. op = of_find_device_by_node(pbm->prom_node);
  898. if (op)
  899. request_irq(op->irqs[0], schizo_pcierr_intr, IRQF_SHARED,
  900. "TOMATILLO PCIERR-A", pbm);
  901. pbm = pbm_for_ino(p, SCHIZO_PCIERR_B_INO);
  902. op = of_find_device_by_node(pbm->prom_node);
  903. if (op)
  904. request_irq(op->irqs[0], schizo_pcierr_intr, IRQF_SHARED,
  905. "TOMATILLO PCIERR-B", pbm);
  906. pbm = pbm_for_ino(p, SCHIZO_SERR_INO);
  907. op = of_find_device_by_node(pbm->prom_node);
  908. if (op)
  909. request_irq(op->irqs[3], schizo_safarierr_intr, IRQF_SHARED,
  910. "TOMATILLO SERR", p);
  911. /* Enable UE and CE interrupts for controller. */
  912. schizo_write(p->pbm_A.controller_regs + SCHIZO_ECC_CTRL,
  913. (SCHIZO_ECCCTRL_EE |
  914. SCHIZO_ECCCTRL_UE |
  915. SCHIZO_ECCCTRL_CE));
  916. schizo_write(p->pbm_B.controller_regs + SCHIZO_ECC_CTRL,
  917. (SCHIZO_ECCCTRL_EE |
  918. SCHIZO_ECCCTRL_UE |
  919. SCHIZO_ECCCTRL_CE));
  920. /* Enable PCI Error interrupts and clear error
  921. * bits.
  922. */
  923. err_mask = (SCHIZO_PCICTRL_BUS_UNUS |
  924. SCHIZO_PCICTRL_TTO_ERR |
  925. SCHIZO_PCICTRL_RTRY_ERR |
  926. SCHIZO_PCICTRL_SERR |
  927. SCHIZO_PCICTRL_EEN);
  928. err_no_mask = SCHIZO_PCICTRL_DTO_ERR;
  929. tmp = schizo_read(p->pbm_A.pbm_regs + SCHIZO_PCI_CTRL);
  930. tmp |= err_mask;
  931. tmp &= ~err_no_mask;
  932. schizo_write(p->pbm_A.pbm_regs + SCHIZO_PCI_CTRL, tmp);
  933. tmp = schizo_read(p->pbm_B.pbm_regs + SCHIZO_PCI_CTRL);
  934. tmp |= err_mask;
  935. tmp &= ~err_no_mask;
  936. schizo_write(p->pbm_B.pbm_regs + SCHIZO_PCI_CTRL, tmp);
  937. err_mask = (SCHIZO_PCIAFSR_PMA | SCHIZO_PCIAFSR_PTA |
  938. SCHIZO_PCIAFSR_PRTRY | SCHIZO_PCIAFSR_PPERR |
  939. SCHIZO_PCIAFSR_PTTO |
  940. SCHIZO_PCIAFSR_SMA | SCHIZO_PCIAFSR_STA |
  941. SCHIZO_PCIAFSR_SRTRY | SCHIZO_PCIAFSR_SPERR |
  942. SCHIZO_PCIAFSR_STTO);
  943. schizo_write(p->pbm_A.pbm_regs + SCHIZO_PCI_AFSR, err_mask);
  944. schizo_write(p->pbm_B.pbm_regs + SCHIZO_PCI_AFSR, err_mask);
  945. err_mask = (BUS_ERROR_BADCMD | BUS_ERROR_SNOOP_GR |
  946. BUS_ERROR_SNOOP_PCI | BUS_ERROR_SNOOP_RD |
  947. BUS_ERROR_SNOOP_RDS | BUS_ERROR_SNOOP_RDSA |
  948. BUS_ERROR_SNOOP_OWN | BUS_ERROR_SNOOP_RDO |
  949. BUS_ERROR_WDATA_PERR | BUS_ERROR_CTRL_PERR |
  950. BUS_ERROR_SNOOP_ERR | BUS_ERROR_JBUS_ILL_B |
  951. BUS_ERROR_JBUS_ILL_C | BUS_ERROR_RD_PERR |
  952. BUS_ERROR_APERR | BUS_ERROR_UNMAP |
  953. BUS_ERROR_BUSERR | BUS_ERROR_TIMEOUT);
  954. schizo_write(p->pbm_A.controller_regs + SCHIZO_SAFARI_ERRCTRL,
  955. (SCHIZO_SAFERRCTRL_EN | err_mask));
  956. schizo_write(p->pbm_B.controller_regs + SCHIZO_SAFARI_ERRCTRL,
  957. (SCHIZO_SAFERRCTRL_EN | err_mask));
  958. schizo_write(p->pbm_A.controller_regs + SCHIZO_SAFARI_IRQCTRL,
  959. (SCHIZO_SAFIRQCTRL_EN | (BUS_ERROR_UNMAP)));
  960. schizo_write(p->pbm_B.controller_regs + SCHIZO_SAFARI_IRQCTRL,
  961. (SCHIZO_SAFIRQCTRL_EN | (BUS_ERROR_UNMAP)));
  962. }
  963. static void schizo_register_error_handlers(struct pci_controller_info *p)
  964. {
  965. struct pci_pbm_info *pbm;
  966. struct of_device *op;
  967. u64 tmp, err_mask, err_no_mask;
  968. /* Schizo IRQ property layout is:
  969. * 0: PCIERR
  970. * 1: UE ERR
  971. * 2: CE ERR
  972. * 3: SERR
  973. * 4: POWER FAIL?
  974. */
  975. pbm = pbm_for_ino(p, SCHIZO_UE_INO);
  976. op = of_find_device_by_node(pbm->prom_node);
  977. if (op)
  978. request_irq(op->irqs[1], schizo_ue_intr, IRQF_SHARED,
  979. "SCHIZO_UE", p);
  980. pbm = pbm_for_ino(p, SCHIZO_CE_INO);
  981. op = of_find_device_by_node(pbm->prom_node);
  982. if (op)
  983. request_irq(op->irqs[2], schizo_ce_intr, IRQF_SHARED,
  984. "SCHIZO CE", p);
  985. pbm = pbm_for_ino(p, SCHIZO_PCIERR_A_INO);
  986. op = of_find_device_by_node(pbm->prom_node);
  987. if (op)
  988. request_irq(op->irqs[0], schizo_pcierr_intr, IRQF_SHARED,
  989. "SCHIZO PCIERR-A", pbm);
  990. pbm = pbm_for_ino(p, SCHIZO_PCIERR_B_INO);
  991. op = of_find_device_by_node(pbm->prom_node);
  992. if (op)
  993. request_irq(op->irqs[0], schizo_pcierr_intr, IRQF_SHARED,
  994. "SCHIZO PCIERR-B", pbm);
  995. pbm = pbm_for_ino(p, SCHIZO_SERR_INO);
  996. op = of_find_device_by_node(pbm->prom_node);
  997. if (op)
  998. request_irq(op->irqs[3], schizo_safarierr_intr, IRQF_SHARED,
  999. "SCHIZO SERR", p);
  1000. /* Enable UE and CE interrupts for controller. */
  1001. schizo_write(p->pbm_A.controller_regs + SCHIZO_ECC_CTRL,
  1002. (SCHIZO_ECCCTRL_EE |
  1003. SCHIZO_ECCCTRL_UE |
  1004. SCHIZO_ECCCTRL_CE));
  1005. err_mask = (SCHIZO_PCICTRL_BUS_UNUS |
  1006. SCHIZO_PCICTRL_ESLCK |
  1007. SCHIZO_PCICTRL_TTO_ERR |
  1008. SCHIZO_PCICTRL_RTRY_ERR |
  1009. SCHIZO_PCICTRL_SBH_ERR |
  1010. SCHIZO_PCICTRL_SERR |
  1011. SCHIZO_PCICTRL_EEN);
  1012. err_no_mask = (SCHIZO_PCICTRL_DTO_ERR |
  1013. SCHIZO_PCICTRL_SBH_INT);
  1014. /* Enable PCI Error interrupts and clear error
  1015. * bits for each PBM.
  1016. */
  1017. tmp = schizo_read(p->pbm_A.pbm_regs + SCHIZO_PCI_CTRL);
  1018. tmp |= err_mask;
  1019. tmp &= ~err_no_mask;
  1020. schizo_write(p->pbm_A.pbm_regs + SCHIZO_PCI_CTRL, tmp);
  1021. schizo_write(p->pbm_A.pbm_regs + SCHIZO_PCI_AFSR,
  1022. (SCHIZO_PCIAFSR_PMA | SCHIZO_PCIAFSR_PTA |
  1023. SCHIZO_PCIAFSR_PRTRY | SCHIZO_PCIAFSR_PPERR |
  1024. SCHIZO_PCIAFSR_PTTO | SCHIZO_PCIAFSR_PUNUS |
  1025. SCHIZO_PCIAFSR_SMA | SCHIZO_PCIAFSR_STA |
  1026. SCHIZO_PCIAFSR_SRTRY | SCHIZO_PCIAFSR_SPERR |
  1027. SCHIZO_PCIAFSR_STTO | SCHIZO_PCIAFSR_SUNUS));
  1028. tmp = schizo_read(p->pbm_B.pbm_regs + SCHIZO_PCI_CTRL);
  1029. tmp |= err_mask;
  1030. tmp &= ~err_no_mask;
  1031. schizo_write(p->pbm_B.pbm_regs + SCHIZO_PCI_CTRL, tmp);
  1032. schizo_write(p->pbm_B.pbm_regs + SCHIZO_PCI_AFSR,
  1033. (SCHIZO_PCIAFSR_PMA | SCHIZO_PCIAFSR_PTA |
  1034. SCHIZO_PCIAFSR_PRTRY | SCHIZO_PCIAFSR_PPERR |
  1035. SCHIZO_PCIAFSR_PTTO | SCHIZO_PCIAFSR_PUNUS |
  1036. SCHIZO_PCIAFSR_SMA | SCHIZO_PCIAFSR_STA |
  1037. SCHIZO_PCIAFSR_SRTRY | SCHIZO_PCIAFSR_SPERR |
  1038. SCHIZO_PCIAFSR_STTO | SCHIZO_PCIAFSR_SUNUS));
  1039. /* Make all Safari error conditions fatal except unmapped
  1040. * errors which we make generate interrupts.
  1041. */
  1042. err_mask = (BUS_ERROR_BADCMD | BUS_ERROR_SSMDIS |
  1043. BUS_ERROR_BADMA | BUS_ERROR_BADMB |
  1044. BUS_ERROR_BADMC |
  1045. BUS_ERROR_CPU1PS | BUS_ERROR_CPU1PB |
  1046. BUS_ERROR_CPU0PS | BUS_ERROR_CPU0PB |
  1047. BUS_ERROR_CIQTO |
  1048. BUS_ERROR_LPQTO | BUS_ERROR_SFPQTO |
  1049. BUS_ERROR_UFPQTO | BUS_ERROR_APERR |
  1050. BUS_ERROR_BUSERR | BUS_ERROR_TIMEOUT |
  1051. BUS_ERROR_ILL);
  1052. #if 1
  1053. /* XXX Something wrong with some Excalibur systems
  1054. * XXX Sun is shipping. The behavior on a 2-cpu
  1055. * XXX machine is that both CPU1 parity error bits
  1056. * XXX are set and are immediately set again when
  1057. * XXX their error status bits are cleared. Just
  1058. * XXX ignore them for now. -DaveM
  1059. */
  1060. err_mask &= ~(BUS_ERROR_CPU1PS | BUS_ERROR_CPU1PB |
  1061. BUS_ERROR_CPU0PS | BUS_ERROR_CPU0PB);
  1062. #endif
  1063. schizo_write(p->pbm_A.controller_regs + SCHIZO_SAFARI_ERRCTRL,
  1064. (SCHIZO_SAFERRCTRL_EN | err_mask));
  1065. schizo_write(p->pbm_A.controller_regs + SCHIZO_SAFARI_IRQCTRL,
  1066. (SCHIZO_SAFIRQCTRL_EN | (BUS_ERROR_UNMAP)));
  1067. }
  1068. static void pbm_config_busmastering(struct pci_pbm_info *pbm)
  1069. {
  1070. u8 *addr;
  1071. /* Set cache-line size to 64 bytes, this is actually
  1072. * a nop but I do it for completeness.
  1073. */
  1074. addr = schizo_pci_config_mkaddr(pbm, pbm->pci_first_busno,
  1075. 0, PCI_CACHE_LINE_SIZE);
  1076. pci_config_write8(addr, 64 / sizeof(u32));
  1077. /* Set PBM latency timer to 64 PCI clocks. */
  1078. addr = schizo_pci_config_mkaddr(pbm, pbm->pci_first_busno,
  1079. 0, PCI_LATENCY_TIMER);
  1080. pci_config_write8(addr, 64);
  1081. }
  1082. static void schizo_scan_bus(struct pci_controller_info *p)
  1083. {
  1084. pbm_config_busmastering(&p->pbm_B);
  1085. p->pbm_B.is_66mhz_capable =
  1086. (of_find_property(p->pbm_B.prom_node, "66mhz-capable", NULL)
  1087. != NULL);
  1088. pbm_config_busmastering(&p->pbm_A);
  1089. p->pbm_A.is_66mhz_capable =
  1090. (of_find_property(p->pbm_A.prom_node, "66mhz-capable", NULL)
  1091. != NULL);
  1092. p->pbm_B.pci_bus = pci_scan_one_pbm(&p->pbm_B);
  1093. p->pbm_A.pci_bus = pci_scan_one_pbm(&p->pbm_A);
  1094. /* After the PCI bus scan is complete, we can register
  1095. * the error interrupt handlers.
  1096. */
  1097. if (p->pbm_B.chip_type == PBM_CHIP_TYPE_TOMATILLO)
  1098. tomatillo_register_error_handlers(p);
  1099. else
  1100. schizo_register_error_handlers(p);
  1101. }
  1102. #define SCHIZO_STRBUF_CONTROL (0x02800UL)
  1103. #define SCHIZO_STRBUF_FLUSH (0x02808UL)
  1104. #define SCHIZO_STRBUF_FSYNC (0x02810UL)
  1105. #define SCHIZO_STRBUF_CTXFLUSH (0x02818UL)
  1106. #define SCHIZO_STRBUF_CTXMATCH (0x10000UL)
  1107. static void schizo_pbm_strbuf_init(struct pci_pbm_info *pbm)
  1108. {
  1109. unsigned long base = pbm->pbm_regs;
  1110. u64 control;
  1111. if (pbm->chip_type == PBM_CHIP_TYPE_TOMATILLO) {
  1112. /* TOMATILLO lacks streaming cache. */
  1113. return;
  1114. }
  1115. /* SCHIZO has context flushing. */
  1116. pbm->stc.strbuf_control = base + SCHIZO_STRBUF_CONTROL;
  1117. pbm->stc.strbuf_pflush = base + SCHIZO_STRBUF_FLUSH;
  1118. pbm->stc.strbuf_fsync = base + SCHIZO_STRBUF_FSYNC;
  1119. pbm->stc.strbuf_ctxflush = base + SCHIZO_STRBUF_CTXFLUSH;
  1120. pbm->stc.strbuf_ctxmatch_base = base + SCHIZO_STRBUF_CTXMATCH;
  1121. pbm->stc.strbuf_flushflag = (volatile unsigned long *)
  1122. ((((unsigned long)&pbm->stc.__flushflag_buf[0])
  1123. + 63UL)
  1124. & ~63UL);
  1125. pbm->stc.strbuf_flushflag_pa = (unsigned long)
  1126. __pa(pbm->stc.strbuf_flushflag);
  1127. /* Turn off LRU locking and diag mode, enable the
  1128. * streaming buffer and leave the rerun-disable
  1129. * setting however OBP set it.
  1130. */
  1131. control = schizo_read(pbm->stc.strbuf_control);
  1132. control &= ~(SCHIZO_STRBUF_CTRL_LPTR |
  1133. SCHIZO_STRBUF_CTRL_LENAB |
  1134. SCHIZO_STRBUF_CTRL_DENAB);
  1135. control |= SCHIZO_STRBUF_CTRL_ENAB;
  1136. schizo_write(pbm->stc.strbuf_control, control);
  1137. pbm->stc.strbuf_enabled = 1;
  1138. }
  1139. #define SCHIZO_IOMMU_CONTROL (0x00200UL)
  1140. #define SCHIZO_IOMMU_TSBBASE (0x00208UL)
  1141. #define SCHIZO_IOMMU_FLUSH (0x00210UL)
  1142. #define SCHIZO_IOMMU_CTXFLUSH (0x00218UL)
  1143. static void schizo_pbm_iommu_init(struct pci_pbm_info *pbm)
  1144. {
  1145. struct pci_iommu *iommu = pbm->iommu;
  1146. unsigned long i, tagbase, database;
  1147. struct property *prop;
  1148. u32 vdma[2], dma_mask;
  1149. u64 control;
  1150. int tsbsize;
  1151. prop = of_find_property(pbm->prom_node, "virtual-dma", NULL);
  1152. if (prop) {
  1153. u32 *val = prop->value;
  1154. vdma[0] = val[0];
  1155. vdma[1] = val[1];
  1156. } else {
  1157. /* No property, use default values. */
  1158. vdma[0] = 0xc0000000;
  1159. vdma[1] = 0x40000000;
  1160. }
  1161. dma_mask = vdma[0];
  1162. switch (vdma[1]) {
  1163. case 0x20000000:
  1164. dma_mask |= 0x1fffffff;
  1165. tsbsize = 64;
  1166. break;
  1167. case 0x40000000:
  1168. dma_mask |= 0x3fffffff;
  1169. tsbsize = 128;
  1170. break;
  1171. case 0x80000000:
  1172. dma_mask |= 0x7fffffff;
  1173. tsbsize = 128;
  1174. break;
  1175. default:
  1176. prom_printf("SCHIZO: strange virtual-dma size.\n");
  1177. prom_halt();
  1178. };
  1179. /* Register addresses, SCHIZO has iommu ctx flushing. */
  1180. iommu->iommu_control = pbm->pbm_regs + SCHIZO_IOMMU_CONTROL;
  1181. iommu->iommu_tsbbase = pbm->pbm_regs + SCHIZO_IOMMU_TSBBASE;
  1182. iommu->iommu_flush = pbm->pbm_regs + SCHIZO_IOMMU_FLUSH;
  1183. iommu->iommu_ctxflush = pbm->pbm_regs + SCHIZO_IOMMU_CTXFLUSH;
  1184. /* We use the main control/status register of SCHIZO as the write
  1185. * completion register.
  1186. */
  1187. iommu->write_complete_reg = pbm->controller_regs + 0x10000UL;
  1188. /*
  1189. * Invalidate TLB Entries.
  1190. */
  1191. control = schizo_read(iommu->iommu_control);
  1192. control |= SCHIZO_IOMMU_CTRL_DENAB;
  1193. schizo_write(iommu->iommu_control, control);
  1194. tagbase = SCHIZO_IOMMU_TAG, database = SCHIZO_IOMMU_DATA;
  1195. for(i = 0; i < 16; i++) {
  1196. schizo_write(pbm->pbm_regs + tagbase + (i * 8UL), 0);
  1197. schizo_write(pbm->pbm_regs + database + (i * 8UL), 0);
  1198. }
  1199. /* Leave diag mode enabled for full-flushing done
  1200. * in pci_iommu.c
  1201. */
  1202. pci_iommu_table_init(iommu, tsbsize * 8 * 1024, vdma[0], dma_mask);
  1203. schizo_write(iommu->iommu_tsbbase, __pa(iommu->page_table));
  1204. control = schizo_read(iommu->iommu_control);
  1205. control &= ~(SCHIZO_IOMMU_CTRL_TSBSZ | SCHIZO_IOMMU_CTRL_TBWSZ);
  1206. switch (tsbsize) {
  1207. case 64:
  1208. control |= SCHIZO_IOMMU_TSBSZ_64K;
  1209. break;
  1210. case 128:
  1211. control |= SCHIZO_IOMMU_TSBSZ_128K;
  1212. break;
  1213. };
  1214. control |= SCHIZO_IOMMU_CTRL_ENAB;
  1215. schizo_write(iommu->iommu_control, control);
  1216. }
  1217. #define SCHIZO_PCI_IRQ_RETRY (0x1a00UL)
  1218. #define SCHIZO_IRQ_RETRY_INF 0xffUL
  1219. #define SCHIZO_PCI_DIAG (0x2020UL)
  1220. #define SCHIZO_PCIDIAG_D_BADECC (1UL << 10UL) /* Disable BAD ECC errors (Schizo) */
  1221. #define SCHIZO_PCIDIAG_D_BYPASS (1UL << 9UL) /* Disable MMU bypass mode (Schizo/Tomatillo) */
  1222. #define SCHIZO_PCIDIAG_D_TTO (1UL << 8UL) /* Disable TTO errors (Schizo/Tomatillo) */
  1223. #define SCHIZO_PCIDIAG_D_RTRYARB (1UL << 7UL) /* Disable retry arbitration (Schizo) */
  1224. #define SCHIZO_PCIDIAG_D_RETRY (1UL << 6UL) /* Disable retry limit (Schizo/Tomatillo) */
  1225. #define SCHIZO_PCIDIAG_D_INTSYNC (1UL << 5UL) /* Disable interrupt/DMA synch (Schizo/Tomatillo) */
  1226. #define SCHIZO_PCIDIAG_I_DMA_PARITY (1UL << 3UL) /* Invert DMA parity (Schizo/Tomatillo) */
  1227. #define SCHIZO_PCIDIAG_I_PIOD_PARITY (1UL << 2UL) /* Invert PIO data parity (Schizo/Tomatillo) */
  1228. #define SCHIZO_PCIDIAG_I_PIOA_PARITY (1UL << 1UL) /* Invert PIO address parity (Schizo/Tomatillo) */
  1229. #define TOMATILLO_PCI_IOC_CSR (0x2248UL)
  1230. #define TOMATILLO_IOC_PART_WPENAB 0x0000000000080000UL
  1231. #define TOMATILLO_IOC_RDMULT_PENAB 0x0000000000040000UL
  1232. #define TOMATILLO_IOC_RDONE_PENAB 0x0000000000020000UL
  1233. #define TOMATILLO_IOC_RDLINE_PENAB 0x0000000000010000UL
  1234. #define TOMATILLO_IOC_RDMULT_PLEN 0x000000000000c000UL
  1235. #define TOMATILLO_IOC_RDMULT_PLEN_SHIFT 14UL
  1236. #define TOMATILLO_IOC_RDONE_PLEN 0x0000000000003000UL
  1237. #define TOMATILLO_IOC_RDONE_PLEN_SHIFT 12UL
  1238. #define TOMATILLO_IOC_RDLINE_PLEN 0x0000000000000c00UL
  1239. #define TOMATILLO_IOC_RDLINE_PLEN_SHIFT 10UL
  1240. #define TOMATILLO_IOC_PREF_OFF 0x00000000000003f8UL
  1241. #define TOMATILLO_IOC_PREF_OFF_SHIFT 3UL
  1242. #define TOMATILLO_IOC_RDMULT_CPENAB 0x0000000000000004UL
  1243. #define TOMATILLO_IOC_RDONE_CPENAB 0x0000000000000002UL
  1244. #define TOMATILLO_IOC_RDLINE_CPENAB 0x0000000000000001UL
  1245. #define TOMATILLO_PCI_IOC_TDIAG (0x2250UL)
  1246. #define TOMATILLO_PCI_IOC_DDIAG (0x2290UL)
  1247. static void schizo_pbm_hw_init(struct pci_pbm_info *pbm)
  1248. {
  1249. struct property *prop;
  1250. u64 tmp;
  1251. schizo_write(pbm->pbm_regs + SCHIZO_PCI_IRQ_RETRY, 5);
  1252. tmp = schizo_read(pbm->pbm_regs + SCHIZO_PCI_CTRL);
  1253. /* Enable arbiter for all PCI slots. */
  1254. tmp |= 0xff;
  1255. if (pbm->chip_type == PBM_CHIP_TYPE_TOMATILLO &&
  1256. pbm->chip_version >= 0x2)
  1257. tmp |= 0x3UL << SCHIZO_PCICTRL_PTO_SHIFT;
  1258. prop = of_find_property(pbm->prom_node, "no-bus-parking", NULL);
  1259. if (!prop)
  1260. tmp |= SCHIZO_PCICTRL_PARK;
  1261. else
  1262. tmp &= ~SCHIZO_PCICTRL_PARK;
  1263. if (pbm->chip_type == PBM_CHIP_TYPE_TOMATILLO &&
  1264. pbm->chip_version <= 0x1)
  1265. tmp |= SCHIZO_PCICTRL_DTO_INT;
  1266. else
  1267. tmp &= ~SCHIZO_PCICTRL_DTO_INT;
  1268. if (pbm->chip_type == PBM_CHIP_TYPE_TOMATILLO)
  1269. tmp |= (SCHIZO_PCICTRL_MRM_PREF |
  1270. SCHIZO_PCICTRL_RDO_PREF |
  1271. SCHIZO_PCICTRL_RDL_PREF);
  1272. schizo_write(pbm->pbm_regs + SCHIZO_PCI_CTRL, tmp);
  1273. tmp = schizo_read(pbm->pbm_regs + SCHIZO_PCI_DIAG);
  1274. tmp &= ~(SCHIZO_PCIDIAG_D_RTRYARB |
  1275. SCHIZO_PCIDIAG_D_RETRY |
  1276. SCHIZO_PCIDIAG_D_INTSYNC);
  1277. schizo_write(pbm->pbm_regs + SCHIZO_PCI_DIAG, tmp);
  1278. if (pbm->chip_type == PBM_CHIP_TYPE_TOMATILLO) {
  1279. /* Clear prefetch lengths to workaround a bug in
  1280. * Jalapeno...
  1281. */
  1282. tmp = (TOMATILLO_IOC_PART_WPENAB |
  1283. (1 << TOMATILLO_IOC_PREF_OFF_SHIFT) |
  1284. TOMATILLO_IOC_RDMULT_CPENAB |
  1285. TOMATILLO_IOC_RDONE_CPENAB |
  1286. TOMATILLO_IOC_RDLINE_CPENAB);
  1287. schizo_write(pbm->pbm_regs + TOMATILLO_PCI_IOC_CSR,
  1288. tmp);
  1289. }
  1290. }
  1291. static void schizo_pbm_init(struct pci_controller_info *p,
  1292. struct device_node *dp, u32 portid,
  1293. int chip_type)
  1294. {
  1295. struct linux_prom64_registers *regs;
  1296. unsigned int *busrange;
  1297. struct pci_pbm_info *pbm;
  1298. const char *chipset_name;
  1299. u32 *ino_bitmap;
  1300. int is_pbm_a;
  1301. switch (chip_type) {
  1302. case PBM_CHIP_TYPE_TOMATILLO:
  1303. chipset_name = "TOMATILLO";
  1304. break;
  1305. case PBM_CHIP_TYPE_SCHIZO_PLUS:
  1306. chipset_name = "SCHIZO+";
  1307. break;
  1308. case PBM_CHIP_TYPE_SCHIZO:
  1309. default:
  1310. chipset_name = "SCHIZO";
  1311. break;
  1312. };
  1313. /* For SCHIZO, three OBP regs:
  1314. * 1) PBM controller regs
  1315. * 2) Schizo front-end controller regs (same for both PBMs)
  1316. * 3) PBM PCI config space
  1317. *
  1318. * For TOMATILLO, four OBP regs:
  1319. * 1) PBM controller regs
  1320. * 2) Tomatillo front-end controller regs
  1321. * 3) PBM PCI config space
  1322. * 4) Ichip regs
  1323. */
  1324. regs = of_get_property(dp, "reg", NULL);
  1325. is_pbm_a = ((regs[0].phys_addr & 0x00700000) == 0x00600000);
  1326. if (is_pbm_a)
  1327. pbm = &p->pbm_A;
  1328. else
  1329. pbm = &p->pbm_B;
  1330. pbm->portid = portid;
  1331. pbm->parent = p;
  1332. pbm->prom_node = dp;
  1333. pbm->pci_first_slot = 1;
  1334. pbm->chip_type = chip_type;
  1335. pbm->chip_version = of_getintprop_default(dp, "version#", 0);
  1336. pbm->chip_revision = of_getintprop_default(dp, "module-version#", 0);
  1337. pbm->pbm_regs = regs[0].phys_addr;
  1338. pbm->controller_regs = regs[1].phys_addr - 0x10000UL;
  1339. if (chip_type == PBM_CHIP_TYPE_TOMATILLO)
  1340. pbm->sync_reg = regs[3].phys_addr + 0x1a18UL;
  1341. pbm->name = dp->full_name;
  1342. printk("%s: %s PCI Bus Module ver[%x:%x]\n",
  1343. pbm->name, chipset_name,
  1344. pbm->chip_version, pbm->chip_revision);
  1345. schizo_pbm_hw_init(pbm);
  1346. pci_determine_mem_io_space(pbm);
  1347. ino_bitmap = of_get_property(dp, "ino-bitmap", NULL);
  1348. pbm->ino_bitmap = (((u64)ino_bitmap[1] << 32UL) |
  1349. ((u64)ino_bitmap[0] << 0UL));
  1350. busrange = of_get_property(dp, "bus-range", NULL);
  1351. pbm->pci_first_busno = busrange[0];
  1352. pbm->pci_last_busno = busrange[1];
  1353. schizo_pbm_iommu_init(pbm);
  1354. schizo_pbm_strbuf_init(pbm);
  1355. }
  1356. static inline int portid_compare(u32 x, u32 y, int chip_type)
  1357. {
  1358. if (chip_type == PBM_CHIP_TYPE_TOMATILLO) {
  1359. if (x == (y ^ 1))
  1360. return 1;
  1361. return 0;
  1362. }
  1363. return (x == y);
  1364. }
  1365. static void __schizo_init(struct device_node *dp, char *model_name, int chip_type)
  1366. {
  1367. struct pci_controller_info *p;
  1368. struct pci_iommu *iommu;
  1369. u32 portid;
  1370. portid = of_getintprop_default(dp, "portid", 0xff);
  1371. for (p = pci_controller_root; p; p = p->next) {
  1372. struct pci_pbm_info *pbm;
  1373. if (p->pbm_A.prom_node && p->pbm_B.prom_node)
  1374. continue;
  1375. pbm = (p->pbm_A.prom_node ?
  1376. &p->pbm_A :
  1377. &p->pbm_B);
  1378. if (portid_compare(pbm->portid, portid, chip_type)) {
  1379. schizo_pbm_init(p, dp, portid, chip_type);
  1380. return;
  1381. }
  1382. }
  1383. p = kzalloc(sizeof(struct pci_controller_info), GFP_ATOMIC);
  1384. if (!p)
  1385. goto memfail;
  1386. iommu = kzalloc(sizeof(struct pci_iommu), GFP_ATOMIC);
  1387. if (!iommu)
  1388. goto memfail;
  1389. p->pbm_A.iommu = iommu;
  1390. iommu = kzalloc(sizeof(struct pci_iommu), GFP_ATOMIC);
  1391. if (!iommu)
  1392. goto memfail;
  1393. p->pbm_B.iommu = iommu;
  1394. p->next = pci_controller_root;
  1395. pci_controller_root = p;
  1396. p->index = pci_num_controllers++;
  1397. p->scan_bus = schizo_scan_bus;
  1398. p->pci_ops = &schizo_ops;
  1399. /* Like PSYCHO we have a 2GB aligned area for memory space. */
  1400. pci_memspace_mask = 0x7fffffffUL;
  1401. schizo_pbm_init(p, dp, portid, chip_type);
  1402. return;
  1403. memfail:
  1404. prom_printf("SCHIZO: Fatal memory allocation error.\n");
  1405. prom_halt();
  1406. }
  1407. void schizo_init(struct device_node *dp, char *model_name)
  1408. {
  1409. __schizo_init(dp, model_name, PBM_CHIP_TYPE_SCHIZO);
  1410. }
  1411. void schizo_plus_init(struct device_node *dp, char *model_name)
  1412. {
  1413. __schizo_init(dp, model_name, PBM_CHIP_TYPE_SCHIZO_PLUS);
  1414. }
  1415. void tomatillo_init(struct device_node *dp, char *model_name)
  1416. {
  1417. __schizo_init(dp, model_name, PBM_CHIP_TYPE_TOMATILLO);
  1418. }