pci_schizo.c 48 KB

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