pci_schizo.c 48 KB

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