pci_psycho.c 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076
  1. /* pci_psycho.c: PSYCHO/U2P specific PCI controller support.
  2. *
  3. * Copyright (C) 1997, 1998, 1999, 2007 David S. Miller (davem@davemloft.net)
  4. * Copyright (C) 1998, 1999 Eddie C. Dost (ecd@skynet.be)
  5. * Copyright (C) 1999 Jakub Jelinek (jakub@redhat.com)
  6. */
  7. #include <linux/kernel.h>
  8. #include <linux/types.h>
  9. #include <linux/pci.h>
  10. #include <linux/init.h>
  11. #include <linux/slab.h>
  12. #include <linux/interrupt.h>
  13. #include <asm/iommu.h>
  14. #include <asm/irq.h>
  15. #include <asm/starfire.h>
  16. #include <asm/prom.h>
  17. #include <asm/of_device.h>
  18. #include <asm/oplib.h>
  19. #include "pci_impl.h"
  20. #include "iommu_common.h"
  21. /* All PSYCHO registers are 64-bits. The following accessor
  22. * routines are how they are accessed. The REG parameter
  23. * is a physical address.
  24. */
  25. #define psycho_read(__reg) \
  26. ({ u64 __ret; \
  27. __asm__ __volatile__("ldxa [%1] %2, %0" \
  28. : "=r" (__ret) \
  29. : "r" (__reg), "i" (ASI_PHYS_BYPASS_EC_E) \
  30. : "memory"); \
  31. __ret; \
  32. })
  33. #define psycho_write(__reg, __val) \
  34. __asm__ __volatile__("stxa %0, [%1] %2" \
  35. : /* no outputs */ \
  36. : "r" (__val), "r" (__reg), \
  37. "i" (ASI_PHYS_BYPASS_EC_E) \
  38. : "memory")
  39. /* Misc. PSYCHO PCI controller register offsets and definitions. */
  40. #define PSYCHO_CONTROL 0x0010UL
  41. #define PSYCHO_CONTROL_IMPL 0xf000000000000000UL /* Implementation of this PSYCHO*/
  42. #define PSYCHO_CONTROL_VER 0x0f00000000000000UL /* Version of this PSYCHO */
  43. #define PSYCHO_CONTROL_MID 0x00f8000000000000UL /* UPA Module ID of PSYCHO */
  44. #define PSYCHO_CONTROL_IGN 0x0007c00000000000UL /* Interrupt Group Number */
  45. #define PSYCHO_CONTROL_RESV 0x00003ffffffffff0UL /* Reserved */
  46. #define PSYCHO_CONTROL_APCKEN 0x0000000000000008UL /* Address Parity Check Enable */
  47. #define PSYCHO_CONTROL_APERR 0x0000000000000004UL /* Incoming System Addr Parerr */
  48. #define PSYCHO_CONTROL_IAP 0x0000000000000002UL /* Invert UPA Parity */
  49. #define PSYCHO_CONTROL_MODE 0x0000000000000001UL /* PSYCHO clock mode */
  50. #define PSYCHO_PCIA_CTRL 0x2000UL
  51. #define PSYCHO_PCIB_CTRL 0x4000UL
  52. #define PSYCHO_PCICTRL_RESV1 0xfffffff000000000UL /* Reserved */
  53. #define PSYCHO_PCICTRL_SBH_ERR 0x0000000800000000UL /* Streaming byte hole error */
  54. #define PSYCHO_PCICTRL_SERR 0x0000000400000000UL /* SERR signal asserted */
  55. #define PSYCHO_PCICTRL_SPEED 0x0000000200000000UL /* PCI speed (1 is U2P clock) */
  56. #define PSYCHO_PCICTRL_RESV2 0x00000001ffc00000UL /* Reserved */
  57. #define PSYCHO_PCICTRL_ARB_PARK 0x0000000000200000UL /* PCI arbitration parking */
  58. #define PSYCHO_PCICTRL_RESV3 0x00000000001ff800UL /* Reserved */
  59. #define PSYCHO_PCICTRL_SBH_INT 0x0000000000000400UL /* Streaming byte hole int enab */
  60. #define PSYCHO_PCICTRL_WEN 0x0000000000000200UL /* Power Mgmt Wake Enable */
  61. #define PSYCHO_PCICTRL_EEN 0x0000000000000100UL /* PCI Error Interrupt Enable */
  62. #define PSYCHO_PCICTRL_RESV4 0x00000000000000c0UL /* Reserved */
  63. #define PSYCHO_PCICTRL_AEN 0x000000000000003fUL /* PCI DVMA Arbitration Enable */
  64. /* U2P Programmer's Manual, page 13-55, configuration space
  65. * address format:
  66. *
  67. * 32 24 23 16 15 11 10 8 7 2 1 0
  68. * ---------------------------------------------------------
  69. * |0 0 0 0 0 0 0 0 1| bus | device | function | reg | 0 0 |
  70. * ---------------------------------------------------------
  71. */
  72. #define PSYCHO_CONFIG_BASE(PBM) \
  73. ((PBM)->config_space | (1UL << 24))
  74. #define PSYCHO_CONFIG_ENCODE(BUS, DEVFN, REG) \
  75. (((unsigned long)(BUS) << 16) | \
  76. ((unsigned long)(DEVFN) << 8) | \
  77. ((unsigned long)(REG)))
  78. static void *psycho_pci_config_mkaddr(struct pci_pbm_info *pbm,
  79. unsigned char bus,
  80. unsigned int devfn,
  81. int where)
  82. {
  83. if (!pbm)
  84. return NULL;
  85. return (void *)
  86. (PSYCHO_CONFIG_BASE(pbm) |
  87. PSYCHO_CONFIG_ENCODE(bus, devfn, where));
  88. }
  89. /* PSYCHO error handling support. */
  90. enum psycho_error_type {
  91. UE_ERR, CE_ERR, PCI_ERR
  92. };
  93. /* Helper function of IOMMU error checking, which checks out
  94. * the state of the streaming buffers. The IOMMU lock is
  95. * held when this is called.
  96. *
  97. * For the PCI error case we know which PBM (and thus which
  98. * streaming buffer) caused the error, but for the uncorrectable
  99. * error case we do not. So we always check both streaming caches.
  100. */
  101. #define PSYCHO_STRBUF_CONTROL_A 0x2800UL
  102. #define PSYCHO_STRBUF_CONTROL_B 0x4800UL
  103. #define PSYCHO_STRBUF_CTRL_LPTR 0x00000000000000f0UL /* LRU Lock Pointer */
  104. #define PSYCHO_STRBUF_CTRL_LENAB 0x0000000000000008UL /* LRU Lock Enable */
  105. #define PSYCHO_STRBUF_CTRL_RRDIS 0x0000000000000004UL /* Rerun Disable */
  106. #define PSYCHO_STRBUF_CTRL_DENAB 0x0000000000000002UL /* Diagnostic Mode Enable */
  107. #define PSYCHO_STRBUF_CTRL_ENAB 0x0000000000000001UL /* Streaming Buffer Enable */
  108. #define PSYCHO_STRBUF_FLUSH_A 0x2808UL
  109. #define PSYCHO_STRBUF_FLUSH_B 0x4808UL
  110. #define PSYCHO_STRBUF_FSYNC_A 0x2810UL
  111. #define PSYCHO_STRBUF_FSYNC_B 0x4810UL
  112. #define PSYCHO_STC_DATA_A 0xb000UL
  113. #define PSYCHO_STC_DATA_B 0xc000UL
  114. #define PSYCHO_STC_ERR_A 0xb400UL
  115. #define PSYCHO_STC_ERR_B 0xc400UL
  116. #define PSYCHO_STCERR_WRITE 0x0000000000000002UL /* Write Error */
  117. #define PSYCHO_STCERR_READ 0x0000000000000001UL /* Read Error */
  118. #define PSYCHO_STC_TAG_A 0xb800UL
  119. #define PSYCHO_STC_TAG_B 0xc800UL
  120. #define PSYCHO_STCTAG_PPN 0x0fffffff00000000UL /* Physical Page Number */
  121. #define PSYCHO_STCTAG_VPN 0x00000000ffffe000UL /* Virtual Page Number */
  122. #define PSYCHO_STCTAG_VALID 0x0000000000000002UL /* Valid */
  123. #define PSYCHO_STCTAG_WRITE 0x0000000000000001UL /* Writable */
  124. #define PSYCHO_STC_LINE_A 0xb900UL
  125. #define PSYCHO_STC_LINE_B 0xc900UL
  126. #define PSYCHO_STCLINE_LINDX 0x0000000001e00000UL /* LRU Index */
  127. #define PSYCHO_STCLINE_SPTR 0x00000000001f8000UL /* Dirty Data Start Pointer */
  128. #define PSYCHO_STCLINE_LADDR 0x0000000000007f00UL /* Line Address */
  129. #define PSYCHO_STCLINE_EPTR 0x00000000000000fcUL /* Dirty Data End Pointer */
  130. #define PSYCHO_STCLINE_VALID 0x0000000000000002UL /* Valid */
  131. #define PSYCHO_STCLINE_FOFN 0x0000000000000001UL /* Fetch Outstanding / Flush Necessary */
  132. static DEFINE_SPINLOCK(stc_buf_lock);
  133. static unsigned long stc_error_buf[128];
  134. static unsigned long stc_tag_buf[16];
  135. static unsigned long stc_line_buf[16];
  136. static void __psycho_check_one_stc(struct pci_pbm_info *pbm,
  137. int is_pbm_a)
  138. {
  139. struct strbuf *strbuf = &pbm->stc;
  140. unsigned long regbase = pbm->controller_regs;
  141. unsigned long err_base, tag_base, line_base;
  142. u64 control;
  143. int i;
  144. if (is_pbm_a) {
  145. err_base = regbase + PSYCHO_STC_ERR_A;
  146. tag_base = regbase + PSYCHO_STC_TAG_A;
  147. line_base = regbase + PSYCHO_STC_LINE_A;
  148. } else {
  149. err_base = regbase + PSYCHO_STC_ERR_B;
  150. tag_base = regbase + PSYCHO_STC_TAG_B;
  151. line_base = regbase + PSYCHO_STC_LINE_B;
  152. }
  153. spin_lock(&stc_buf_lock);
  154. /* This is __REALLY__ dangerous. When we put the
  155. * streaming buffer into diagnostic mode to probe
  156. * it's tags and error status, we _must_ clear all
  157. * of the line tag valid bits before re-enabling
  158. * the streaming buffer. If any dirty data lives
  159. * in the STC when we do this, we will end up
  160. * invalidating it before it has a chance to reach
  161. * main memory.
  162. */
  163. control = psycho_read(strbuf->strbuf_control);
  164. psycho_write(strbuf->strbuf_control,
  165. (control | PSYCHO_STRBUF_CTRL_DENAB));
  166. for (i = 0; i < 128; i++) {
  167. unsigned long val;
  168. val = psycho_read(err_base + (i * 8UL));
  169. psycho_write(err_base + (i * 8UL), 0UL);
  170. stc_error_buf[i] = val;
  171. }
  172. for (i = 0; i < 16; i++) {
  173. stc_tag_buf[i] = psycho_read(tag_base + (i * 8UL));
  174. stc_line_buf[i] = psycho_read(line_base + (i * 8UL));
  175. psycho_write(tag_base + (i * 8UL), 0UL);
  176. psycho_write(line_base + (i * 8UL), 0UL);
  177. }
  178. /* OK, state is logged, exit diagnostic mode. */
  179. psycho_write(strbuf->strbuf_control, control);
  180. for (i = 0; i < 16; i++) {
  181. int j, saw_error, first, last;
  182. saw_error = 0;
  183. first = i * 8;
  184. last = first + 8;
  185. for (j = first; j < last; j++) {
  186. unsigned long errval = stc_error_buf[j];
  187. if (errval != 0) {
  188. saw_error++;
  189. printk("%s: STC_ERR(%d)[wr(%d)rd(%d)]\n",
  190. pbm->name,
  191. j,
  192. (errval & PSYCHO_STCERR_WRITE) ? 1 : 0,
  193. (errval & PSYCHO_STCERR_READ) ? 1 : 0);
  194. }
  195. }
  196. if (saw_error != 0) {
  197. unsigned long tagval = stc_tag_buf[i];
  198. unsigned long lineval = stc_line_buf[i];
  199. printk("%s: STC_TAG(%d)[PA(%016lx)VA(%08lx)V(%d)W(%d)]\n",
  200. pbm->name,
  201. i,
  202. ((tagval & PSYCHO_STCTAG_PPN) >> 19UL),
  203. (tagval & PSYCHO_STCTAG_VPN),
  204. ((tagval & PSYCHO_STCTAG_VALID) ? 1 : 0),
  205. ((tagval & PSYCHO_STCTAG_WRITE) ? 1 : 0));
  206. printk("%s: STC_LINE(%d)[LIDX(%lx)SP(%lx)LADDR(%lx)EP(%lx)"
  207. "V(%d)FOFN(%d)]\n",
  208. pbm->name,
  209. i,
  210. ((lineval & PSYCHO_STCLINE_LINDX) >> 21UL),
  211. ((lineval & PSYCHO_STCLINE_SPTR) >> 15UL),
  212. ((lineval & PSYCHO_STCLINE_LADDR) >> 8UL),
  213. ((lineval & PSYCHO_STCLINE_EPTR) >> 2UL),
  214. ((lineval & PSYCHO_STCLINE_VALID) ? 1 : 0),
  215. ((lineval & PSYCHO_STCLINE_FOFN) ? 1 : 0));
  216. }
  217. }
  218. spin_unlock(&stc_buf_lock);
  219. }
  220. static void __psycho_check_stc_error(struct pci_pbm_info *pbm,
  221. unsigned long afsr,
  222. unsigned long afar,
  223. enum psycho_error_type type)
  224. {
  225. __psycho_check_one_stc(pbm,
  226. (pbm == &pbm->parent->pbm_A));
  227. }
  228. /* When an Uncorrectable Error or a PCI Error happens, we
  229. * interrogate the IOMMU state to see if it is the cause.
  230. */
  231. #define PSYCHO_IOMMU_CONTROL 0x0200UL
  232. #define PSYCHO_IOMMU_CTRL_RESV 0xfffffffff9000000UL /* Reserved */
  233. #define PSYCHO_IOMMU_CTRL_XLTESTAT 0x0000000006000000UL /* Translation Error Status */
  234. #define PSYCHO_IOMMU_CTRL_XLTEERR 0x0000000001000000UL /* Translation Error encountered */
  235. #define PSYCHO_IOMMU_CTRL_LCKEN 0x0000000000800000UL /* Enable translation locking */
  236. #define PSYCHO_IOMMU_CTRL_LCKPTR 0x0000000000780000UL /* Translation lock pointer */
  237. #define PSYCHO_IOMMU_CTRL_TSBSZ 0x0000000000070000UL /* TSB Size */
  238. #define PSYCHO_IOMMU_TSBSZ_1K 0x0000000000000000UL /* TSB Table 1024 8-byte entries */
  239. #define PSYCHO_IOMMU_TSBSZ_2K 0x0000000000010000UL /* TSB Table 2048 8-byte entries */
  240. #define PSYCHO_IOMMU_TSBSZ_4K 0x0000000000020000UL /* TSB Table 4096 8-byte entries */
  241. #define PSYCHO_IOMMU_TSBSZ_8K 0x0000000000030000UL /* TSB Table 8192 8-byte entries */
  242. #define PSYCHO_IOMMU_TSBSZ_16K 0x0000000000040000UL /* TSB Table 16k 8-byte entries */
  243. #define PSYCHO_IOMMU_TSBSZ_32K 0x0000000000050000UL /* TSB Table 32k 8-byte entries */
  244. #define PSYCHO_IOMMU_TSBSZ_64K 0x0000000000060000UL /* TSB Table 64k 8-byte entries */
  245. #define PSYCHO_IOMMU_TSBSZ_128K 0x0000000000070000UL /* TSB Table 128k 8-byte entries */
  246. #define PSYCHO_IOMMU_CTRL_RESV2 0x000000000000fff8UL /* Reserved */
  247. #define PSYCHO_IOMMU_CTRL_TBWSZ 0x0000000000000004UL /* Assumed page size, 0=8k 1=64k */
  248. #define PSYCHO_IOMMU_CTRL_DENAB 0x0000000000000002UL /* Diagnostic mode enable */
  249. #define PSYCHO_IOMMU_CTRL_ENAB 0x0000000000000001UL /* IOMMU Enable */
  250. #define PSYCHO_IOMMU_TSBBASE 0x0208UL
  251. #define PSYCHO_IOMMU_FLUSH 0x0210UL
  252. #define PSYCHO_IOMMU_TAG 0xa580UL
  253. #define PSYCHO_IOMMU_TAG_ERRSTS (0x3UL << 23UL)
  254. #define PSYCHO_IOMMU_TAG_ERR (0x1UL << 22UL)
  255. #define PSYCHO_IOMMU_TAG_WRITE (0x1UL << 21UL)
  256. #define PSYCHO_IOMMU_TAG_STREAM (0x1UL << 20UL)
  257. #define PSYCHO_IOMMU_TAG_SIZE (0x1UL << 19UL)
  258. #define PSYCHO_IOMMU_TAG_VPAGE 0x7ffffUL
  259. #define PSYCHO_IOMMU_DATA 0xa600UL
  260. #define PSYCHO_IOMMU_DATA_VALID (1UL << 30UL)
  261. #define PSYCHO_IOMMU_DATA_CACHE (1UL << 28UL)
  262. #define PSYCHO_IOMMU_DATA_PPAGE 0xfffffffUL
  263. static void psycho_check_iommu_error(struct pci_pbm_info *pbm,
  264. unsigned long afsr,
  265. unsigned long afar,
  266. enum psycho_error_type type)
  267. {
  268. struct iommu *iommu = pbm->iommu;
  269. unsigned long iommu_tag[16];
  270. unsigned long iommu_data[16];
  271. unsigned long flags;
  272. u64 control;
  273. int i;
  274. spin_lock_irqsave(&iommu->lock, flags);
  275. control = psycho_read(iommu->iommu_control);
  276. if (control & PSYCHO_IOMMU_CTRL_XLTEERR) {
  277. char *type_string;
  278. /* Clear the error encountered bit. */
  279. control &= ~PSYCHO_IOMMU_CTRL_XLTEERR;
  280. psycho_write(iommu->iommu_control, control);
  281. switch((control & PSYCHO_IOMMU_CTRL_XLTESTAT) >> 25UL) {
  282. case 0:
  283. type_string = "Protection Error";
  284. break;
  285. case 1:
  286. type_string = "Invalid Error";
  287. break;
  288. case 2:
  289. type_string = "TimeOut Error";
  290. break;
  291. case 3:
  292. default:
  293. type_string = "ECC Error";
  294. break;
  295. };
  296. printk("%s: IOMMU Error, type[%s]\n",
  297. pbm->name, type_string);
  298. /* Put the IOMMU into diagnostic mode and probe
  299. * it's TLB for entries with error status.
  300. *
  301. * It is very possible for another DVMA to occur
  302. * while we do this probe, and corrupt the system
  303. * further. But we are so screwed at this point
  304. * that we are likely to crash hard anyways, so
  305. * get as much diagnostic information to the
  306. * console as we can.
  307. */
  308. psycho_write(iommu->iommu_control,
  309. control | PSYCHO_IOMMU_CTRL_DENAB);
  310. for (i = 0; i < 16; i++) {
  311. unsigned long base = pbm->controller_regs;
  312. iommu_tag[i] =
  313. psycho_read(base + PSYCHO_IOMMU_TAG + (i * 8UL));
  314. iommu_data[i] =
  315. psycho_read(base + PSYCHO_IOMMU_DATA + (i * 8UL));
  316. /* Now clear out the entry. */
  317. psycho_write(base + PSYCHO_IOMMU_TAG + (i * 8UL), 0);
  318. psycho_write(base + PSYCHO_IOMMU_DATA + (i * 8UL), 0);
  319. }
  320. /* Leave diagnostic mode. */
  321. psycho_write(iommu->iommu_control, control);
  322. for (i = 0; i < 16; i++) {
  323. unsigned long tag, data;
  324. tag = iommu_tag[i];
  325. if (!(tag & PSYCHO_IOMMU_TAG_ERR))
  326. continue;
  327. data = iommu_data[i];
  328. switch((tag & PSYCHO_IOMMU_TAG_ERRSTS) >> 23UL) {
  329. case 0:
  330. type_string = "Protection Error";
  331. break;
  332. case 1:
  333. type_string = "Invalid Error";
  334. break;
  335. case 2:
  336. type_string = "TimeOut Error";
  337. break;
  338. case 3:
  339. default:
  340. type_string = "ECC Error";
  341. break;
  342. };
  343. printk("%s: IOMMU TAG(%d)[error(%s) wr(%d) str(%d) sz(%dK) vpg(%08lx)]\n",
  344. pbm->name, i, type_string,
  345. ((tag & PSYCHO_IOMMU_TAG_WRITE) ? 1 : 0),
  346. ((tag & PSYCHO_IOMMU_TAG_STREAM) ? 1 : 0),
  347. ((tag & PSYCHO_IOMMU_TAG_SIZE) ? 64 : 8),
  348. (tag & PSYCHO_IOMMU_TAG_VPAGE) << IOMMU_PAGE_SHIFT);
  349. printk("%s: IOMMU DATA(%d)[valid(%d) cache(%d) ppg(%016lx)]\n",
  350. pbm->name, i,
  351. ((data & PSYCHO_IOMMU_DATA_VALID) ? 1 : 0),
  352. ((data & PSYCHO_IOMMU_DATA_CACHE) ? 1 : 0),
  353. (data & PSYCHO_IOMMU_DATA_PPAGE) << IOMMU_PAGE_SHIFT);
  354. }
  355. }
  356. __psycho_check_stc_error(pbm, afsr, afar, type);
  357. spin_unlock_irqrestore(&iommu->lock, flags);
  358. }
  359. /* Uncorrectable Errors. Cause of the error and the address are
  360. * recorded in the UE_AFSR and UE_AFAR of PSYCHO. They are errors
  361. * relating to UPA interface transactions.
  362. */
  363. #define PSYCHO_UE_AFSR 0x0030UL
  364. #define PSYCHO_UEAFSR_PPIO 0x8000000000000000UL /* Primary PIO is cause */
  365. #define PSYCHO_UEAFSR_PDRD 0x4000000000000000UL /* Primary DVMA read is cause */
  366. #define PSYCHO_UEAFSR_PDWR 0x2000000000000000UL /* Primary DVMA write is cause */
  367. #define PSYCHO_UEAFSR_SPIO 0x1000000000000000UL /* Secondary PIO is cause */
  368. #define PSYCHO_UEAFSR_SDRD 0x0800000000000000UL /* Secondary DVMA read is cause */
  369. #define PSYCHO_UEAFSR_SDWR 0x0400000000000000UL /* Secondary DVMA write is cause*/
  370. #define PSYCHO_UEAFSR_RESV1 0x03ff000000000000UL /* Reserved */
  371. #define PSYCHO_UEAFSR_BMSK 0x0000ffff00000000UL /* Bytemask of failed transfer */
  372. #define PSYCHO_UEAFSR_DOFF 0x00000000e0000000UL /* Doubleword Offset */
  373. #define PSYCHO_UEAFSR_MID 0x000000001f000000UL /* UPA MID causing the fault */
  374. #define PSYCHO_UEAFSR_BLK 0x0000000000800000UL /* Trans was block operation */
  375. #define PSYCHO_UEAFSR_RESV2 0x00000000007fffffUL /* Reserved */
  376. #define PSYCHO_UE_AFAR 0x0038UL
  377. static irqreturn_t psycho_ue_intr(int irq, void *dev_id)
  378. {
  379. struct pci_pbm_info *pbm = dev_id;
  380. struct pci_controller_info *p = pbm->parent;
  381. unsigned long afsr_reg = pbm->controller_regs + PSYCHO_UE_AFSR;
  382. unsigned long afar_reg = pbm->controller_regs + PSYCHO_UE_AFAR;
  383. unsigned long afsr, afar, error_bits;
  384. int reported;
  385. /* Latch uncorrectable error status. */
  386. afar = psycho_read(afar_reg);
  387. afsr = psycho_read(afsr_reg);
  388. /* Clear the primary/secondary error status bits. */
  389. error_bits = afsr &
  390. (PSYCHO_UEAFSR_PPIO | PSYCHO_UEAFSR_PDRD | PSYCHO_UEAFSR_PDWR |
  391. PSYCHO_UEAFSR_SPIO | PSYCHO_UEAFSR_SDRD | PSYCHO_UEAFSR_SDWR);
  392. if (!error_bits)
  393. return IRQ_NONE;
  394. psycho_write(afsr_reg, error_bits);
  395. /* Log the error. */
  396. printk("%s: Uncorrectable Error, primary error type[%s]\n",
  397. pbm->name,
  398. (((error_bits & PSYCHO_UEAFSR_PPIO) ?
  399. "PIO" :
  400. ((error_bits & PSYCHO_UEAFSR_PDRD) ?
  401. "DMA Read" :
  402. ((error_bits & PSYCHO_UEAFSR_PDWR) ?
  403. "DMA Write" : "???")))));
  404. printk("%s: bytemask[%04lx] dword_offset[%lx] UPA_MID[%02lx] was_block(%d)\n",
  405. pbm->name,
  406. (afsr & PSYCHO_UEAFSR_BMSK) >> 32UL,
  407. (afsr & PSYCHO_UEAFSR_DOFF) >> 29UL,
  408. (afsr & PSYCHO_UEAFSR_MID) >> 24UL,
  409. ((afsr & PSYCHO_UEAFSR_BLK) ? 1 : 0));
  410. printk("%s: UE AFAR [%016lx]\n", pbm->name, afar);
  411. printk("%s: UE Secondary errors [", pbm->name);
  412. reported = 0;
  413. if (afsr & PSYCHO_UEAFSR_SPIO) {
  414. reported++;
  415. printk("(PIO)");
  416. }
  417. if (afsr & PSYCHO_UEAFSR_SDRD) {
  418. reported++;
  419. printk("(DMA Read)");
  420. }
  421. if (afsr & PSYCHO_UEAFSR_SDWR) {
  422. reported++;
  423. printk("(DMA Write)");
  424. }
  425. if (!reported)
  426. printk("(none)");
  427. printk("]\n");
  428. /* Interrogate both IOMMUs for error status. */
  429. psycho_check_iommu_error(&p->pbm_A, afsr, afar, UE_ERR);
  430. psycho_check_iommu_error(&p->pbm_B, afsr, afar, UE_ERR);
  431. return IRQ_HANDLED;
  432. }
  433. /* Correctable Errors. */
  434. #define PSYCHO_CE_AFSR 0x0040UL
  435. #define PSYCHO_CEAFSR_PPIO 0x8000000000000000UL /* Primary PIO is cause */
  436. #define PSYCHO_CEAFSR_PDRD 0x4000000000000000UL /* Primary DVMA read is cause */
  437. #define PSYCHO_CEAFSR_PDWR 0x2000000000000000UL /* Primary DVMA write is cause */
  438. #define PSYCHO_CEAFSR_SPIO 0x1000000000000000UL /* Secondary PIO is cause */
  439. #define PSYCHO_CEAFSR_SDRD 0x0800000000000000UL /* Secondary DVMA read is cause */
  440. #define PSYCHO_CEAFSR_SDWR 0x0400000000000000UL /* Secondary DVMA write is cause*/
  441. #define PSYCHO_CEAFSR_RESV1 0x0300000000000000UL /* Reserved */
  442. #define PSYCHO_CEAFSR_ESYND 0x00ff000000000000UL /* Syndrome Bits */
  443. #define PSYCHO_CEAFSR_BMSK 0x0000ffff00000000UL /* Bytemask of failed transfer */
  444. #define PSYCHO_CEAFSR_DOFF 0x00000000e0000000UL /* Double Offset */
  445. #define PSYCHO_CEAFSR_MID 0x000000001f000000UL /* UPA MID causing the fault */
  446. #define PSYCHO_CEAFSR_BLK 0x0000000000800000UL /* Trans was block operation */
  447. #define PSYCHO_CEAFSR_RESV2 0x00000000007fffffUL /* Reserved */
  448. #define PSYCHO_CE_AFAR 0x0040UL
  449. static irqreturn_t psycho_ce_intr(int irq, void *dev_id)
  450. {
  451. struct pci_pbm_info *pbm = dev_id;
  452. unsigned long afsr_reg = pbm->controller_regs + PSYCHO_CE_AFSR;
  453. unsigned long afar_reg = pbm->controller_regs + PSYCHO_CE_AFAR;
  454. unsigned long afsr, afar, error_bits;
  455. int reported;
  456. /* Latch error status. */
  457. afar = psycho_read(afar_reg);
  458. afsr = psycho_read(afsr_reg);
  459. /* Clear primary/secondary error status bits. */
  460. error_bits = afsr &
  461. (PSYCHO_CEAFSR_PPIO | PSYCHO_CEAFSR_PDRD | PSYCHO_CEAFSR_PDWR |
  462. PSYCHO_CEAFSR_SPIO | PSYCHO_CEAFSR_SDRD | PSYCHO_CEAFSR_SDWR);
  463. if (!error_bits)
  464. return IRQ_NONE;
  465. psycho_write(afsr_reg, error_bits);
  466. /* Log the error. */
  467. printk("%s: Correctable Error, primary error type[%s]\n",
  468. pbm->name,
  469. (((error_bits & PSYCHO_CEAFSR_PPIO) ?
  470. "PIO" :
  471. ((error_bits & PSYCHO_CEAFSR_PDRD) ?
  472. "DMA Read" :
  473. ((error_bits & PSYCHO_CEAFSR_PDWR) ?
  474. "DMA Write" : "???")))));
  475. /* XXX Use syndrome and afar to print out module string just like
  476. * XXX UDB CE trap handler does... -DaveM
  477. */
  478. printk("%s: syndrome[%02lx] bytemask[%04lx] dword_offset[%lx] "
  479. "UPA_MID[%02lx] was_block(%d)\n",
  480. pbm->name,
  481. (afsr & PSYCHO_CEAFSR_ESYND) >> 48UL,
  482. (afsr & PSYCHO_CEAFSR_BMSK) >> 32UL,
  483. (afsr & PSYCHO_CEAFSR_DOFF) >> 29UL,
  484. (afsr & PSYCHO_CEAFSR_MID) >> 24UL,
  485. ((afsr & PSYCHO_CEAFSR_BLK) ? 1 : 0));
  486. printk("%s: CE AFAR [%016lx]\n", pbm->name, afar);
  487. printk("%s: CE Secondary errors [", pbm->name);
  488. reported = 0;
  489. if (afsr & PSYCHO_CEAFSR_SPIO) {
  490. reported++;
  491. printk("(PIO)");
  492. }
  493. if (afsr & PSYCHO_CEAFSR_SDRD) {
  494. reported++;
  495. printk("(DMA Read)");
  496. }
  497. if (afsr & PSYCHO_CEAFSR_SDWR) {
  498. reported++;
  499. printk("(DMA Write)");
  500. }
  501. if (!reported)
  502. printk("(none)");
  503. printk("]\n");
  504. return IRQ_HANDLED;
  505. }
  506. /* PCI Errors. They are signalled by the PCI bus module since they
  507. * are associated with a specific bus segment.
  508. */
  509. #define PSYCHO_PCI_AFSR_A 0x2010UL
  510. #define PSYCHO_PCI_AFSR_B 0x4010UL
  511. #define PSYCHO_PCIAFSR_PMA 0x8000000000000000UL /* Primary Master Abort Error */
  512. #define PSYCHO_PCIAFSR_PTA 0x4000000000000000UL /* Primary Target Abort Error */
  513. #define PSYCHO_PCIAFSR_PRTRY 0x2000000000000000UL /* Primary Excessive Retries */
  514. #define PSYCHO_PCIAFSR_PPERR 0x1000000000000000UL /* Primary Parity Error */
  515. #define PSYCHO_PCIAFSR_SMA 0x0800000000000000UL /* Secondary Master Abort Error */
  516. #define PSYCHO_PCIAFSR_STA 0x0400000000000000UL /* Secondary Target Abort Error */
  517. #define PSYCHO_PCIAFSR_SRTRY 0x0200000000000000UL /* Secondary Excessive Retries */
  518. #define PSYCHO_PCIAFSR_SPERR 0x0100000000000000UL /* Secondary Parity Error */
  519. #define PSYCHO_PCIAFSR_RESV1 0x00ff000000000000UL /* Reserved */
  520. #define PSYCHO_PCIAFSR_BMSK 0x0000ffff00000000UL /* Bytemask of failed transfer */
  521. #define PSYCHO_PCIAFSR_BLK 0x0000000080000000UL /* Trans was block operation */
  522. #define PSYCHO_PCIAFSR_RESV2 0x0000000040000000UL /* Reserved */
  523. #define PSYCHO_PCIAFSR_MID 0x000000003e000000UL /* MID causing the error */
  524. #define PSYCHO_PCIAFSR_RESV3 0x0000000001ffffffUL /* Reserved */
  525. #define PSYCHO_PCI_AFAR_A 0x2018UL
  526. #define PSYCHO_PCI_AFAR_B 0x4018UL
  527. static irqreturn_t psycho_pcierr_intr_other(struct pci_pbm_info *pbm, int is_pbm_a)
  528. {
  529. unsigned long csr_reg, csr, csr_error_bits;
  530. irqreturn_t ret = IRQ_NONE;
  531. u16 stat;
  532. if (is_pbm_a) {
  533. csr_reg = pbm->controller_regs + PSYCHO_PCIA_CTRL;
  534. } else {
  535. csr_reg = pbm->controller_regs + PSYCHO_PCIB_CTRL;
  536. }
  537. csr = psycho_read(csr_reg);
  538. csr_error_bits =
  539. csr & (PSYCHO_PCICTRL_SBH_ERR | PSYCHO_PCICTRL_SERR);
  540. if (csr_error_bits) {
  541. /* Clear the errors. */
  542. psycho_write(csr_reg, csr);
  543. /* Log 'em. */
  544. if (csr_error_bits & PSYCHO_PCICTRL_SBH_ERR)
  545. printk("%s: PCI streaming byte hole error asserted.\n",
  546. pbm->name);
  547. if (csr_error_bits & PSYCHO_PCICTRL_SERR)
  548. printk("%s: PCI SERR signal asserted.\n", pbm->name);
  549. ret = IRQ_HANDLED;
  550. }
  551. pci_read_config_word(pbm->pci_bus->self, PCI_STATUS, &stat);
  552. if (stat & (PCI_STATUS_PARITY |
  553. PCI_STATUS_SIG_TARGET_ABORT |
  554. PCI_STATUS_REC_TARGET_ABORT |
  555. PCI_STATUS_REC_MASTER_ABORT |
  556. PCI_STATUS_SIG_SYSTEM_ERROR)) {
  557. printk("%s: PCI bus error, PCI_STATUS[%04x]\n",
  558. pbm->name, stat);
  559. pci_write_config_word(pbm->pci_bus->self, PCI_STATUS, 0xffff);
  560. ret = IRQ_HANDLED;
  561. }
  562. return ret;
  563. }
  564. static irqreturn_t psycho_pcierr_intr(int irq, void *dev_id)
  565. {
  566. struct pci_pbm_info *pbm = dev_id;
  567. struct pci_controller_info *p = pbm->parent;
  568. unsigned long afsr_reg, afar_reg;
  569. unsigned long afsr, afar, error_bits;
  570. int is_pbm_a, reported;
  571. is_pbm_a = (pbm == &pbm->parent->pbm_A);
  572. if (is_pbm_a) {
  573. afsr_reg = p->pbm_A.controller_regs + PSYCHO_PCI_AFSR_A;
  574. afar_reg = p->pbm_A.controller_regs + PSYCHO_PCI_AFAR_A;
  575. } else {
  576. afsr_reg = p->pbm_A.controller_regs + PSYCHO_PCI_AFSR_B;
  577. afar_reg = p->pbm_A.controller_regs + PSYCHO_PCI_AFAR_B;
  578. }
  579. /* Latch error status. */
  580. afar = psycho_read(afar_reg);
  581. afsr = psycho_read(afsr_reg);
  582. /* Clear primary/secondary error status bits. */
  583. error_bits = afsr &
  584. (PSYCHO_PCIAFSR_PMA | PSYCHO_PCIAFSR_PTA |
  585. PSYCHO_PCIAFSR_PRTRY | PSYCHO_PCIAFSR_PPERR |
  586. PSYCHO_PCIAFSR_SMA | PSYCHO_PCIAFSR_STA |
  587. PSYCHO_PCIAFSR_SRTRY | PSYCHO_PCIAFSR_SPERR);
  588. if (!error_bits)
  589. return psycho_pcierr_intr_other(pbm, is_pbm_a);
  590. psycho_write(afsr_reg, error_bits);
  591. /* Log the error. */
  592. printk("%s: PCI Error, primary error type[%s]\n",
  593. pbm->name,
  594. (((error_bits & PSYCHO_PCIAFSR_PMA) ?
  595. "Master Abort" :
  596. ((error_bits & PSYCHO_PCIAFSR_PTA) ?
  597. "Target Abort" :
  598. ((error_bits & PSYCHO_PCIAFSR_PRTRY) ?
  599. "Excessive Retries" :
  600. ((error_bits & PSYCHO_PCIAFSR_PPERR) ?
  601. "Parity Error" : "???"))))));
  602. printk("%s: bytemask[%04lx] UPA_MID[%02lx] was_block(%d)\n",
  603. pbm->name,
  604. (afsr & PSYCHO_PCIAFSR_BMSK) >> 32UL,
  605. (afsr & PSYCHO_PCIAFSR_MID) >> 25UL,
  606. (afsr & PSYCHO_PCIAFSR_BLK) ? 1 : 0);
  607. printk("%s: PCI AFAR [%016lx]\n", pbm->name, afar);
  608. printk("%s: PCI Secondary errors [", pbm->name);
  609. reported = 0;
  610. if (afsr & PSYCHO_PCIAFSR_SMA) {
  611. reported++;
  612. printk("(Master Abort)");
  613. }
  614. if (afsr & PSYCHO_PCIAFSR_STA) {
  615. reported++;
  616. printk("(Target Abort)");
  617. }
  618. if (afsr & PSYCHO_PCIAFSR_SRTRY) {
  619. reported++;
  620. printk("(Excessive Retries)");
  621. }
  622. if (afsr & PSYCHO_PCIAFSR_SPERR) {
  623. reported++;
  624. printk("(Parity Error)");
  625. }
  626. if (!reported)
  627. printk("(none)");
  628. printk("]\n");
  629. /* For the error types shown, scan PBM's PCI bus for devices
  630. * which have logged that error type.
  631. */
  632. /* If we see a Target Abort, this could be the result of an
  633. * IOMMU translation error of some sort. It is extremely
  634. * useful to log this information as usually it indicates
  635. * a bug in the IOMMU support code or a PCI device driver.
  636. */
  637. if (error_bits & (PSYCHO_PCIAFSR_PTA | PSYCHO_PCIAFSR_STA)) {
  638. psycho_check_iommu_error(pbm, afsr, afar, PCI_ERR);
  639. pci_scan_for_target_abort(pbm, pbm->pci_bus);
  640. }
  641. if (error_bits & (PSYCHO_PCIAFSR_PMA | PSYCHO_PCIAFSR_SMA))
  642. pci_scan_for_master_abort(pbm, pbm->pci_bus);
  643. /* For excessive retries, PSYCHO/PBM will abort the device
  644. * and there is no way to specifically check for excessive
  645. * retries in the config space status registers. So what
  646. * we hope is that we'll catch it via the master/target
  647. * abort events.
  648. */
  649. if (error_bits & (PSYCHO_PCIAFSR_PPERR | PSYCHO_PCIAFSR_SPERR))
  650. pci_scan_for_parity_error(pbm, pbm->pci_bus);
  651. return IRQ_HANDLED;
  652. }
  653. /* XXX What about PowerFail/PowerManagement??? -DaveM */
  654. #define PSYCHO_ECC_CTRL 0x0020
  655. #define PSYCHO_ECCCTRL_EE 0x8000000000000000UL /* Enable ECC Checking */
  656. #define PSYCHO_ECCCTRL_UE 0x4000000000000000UL /* Enable UE Interrupts */
  657. #define PSYCHO_ECCCTRL_CE 0x2000000000000000UL /* Enable CE INterrupts */
  658. static void psycho_register_error_handlers(struct pci_pbm_info *pbm)
  659. {
  660. struct of_device *op = of_find_device_by_node(pbm->prom_node);
  661. unsigned long base = pbm->controller_regs;
  662. u64 tmp;
  663. int err;
  664. if (!op)
  665. return;
  666. /* Psycho interrupt property order is:
  667. * 0: PCIERR INO for this PBM
  668. * 1: UE ERR
  669. * 2: CE ERR
  670. * 3: POWER FAIL
  671. * 4: SPARE HARDWARE
  672. * 5: POWER MANAGEMENT
  673. */
  674. if (op->num_irqs < 6)
  675. return;
  676. /* We really mean to ignore the return result here. Two
  677. * PCI controller share the same interrupt numbers and
  678. * drive the same front-end hardware. Whichever of the
  679. * two get in here first will register the IRQ handler
  680. * the second will just error out since we do not pass in
  681. * IRQF_SHARED.
  682. */
  683. err = request_irq(op->irqs[1], psycho_ue_intr, 0,
  684. "PSYCHO_UE", pbm);
  685. err = request_irq(op->irqs[2], psycho_ce_intr, 0,
  686. "PSYCHO_CE", pbm);
  687. /* This one, however, ought not to fail. We can just warn
  688. * about it since the system can still operate properly even
  689. * if this fails.
  690. */
  691. err = request_irq(op->irqs[0], psycho_pcierr_intr, 0,
  692. "PSYCHO_PCIERR", pbm);
  693. if (err)
  694. printk(KERN_WARNING "%s: Could not register PCIERR, "
  695. "err=%d\n", pbm->name, err);
  696. /* Enable UE and CE interrupts for controller. */
  697. psycho_write(base + PSYCHO_ECC_CTRL,
  698. (PSYCHO_ECCCTRL_EE |
  699. PSYCHO_ECCCTRL_UE |
  700. PSYCHO_ECCCTRL_CE));
  701. /* Enable PCI Error interrupts and clear error
  702. * bits for each PBM.
  703. */
  704. tmp = psycho_read(base + PSYCHO_PCIA_CTRL);
  705. tmp |= (PSYCHO_PCICTRL_SERR |
  706. PSYCHO_PCICTRL_SBH_ERR |
  707. PSYCHO_PCICTRL_EEN);
  708. tmp &= ~(PSYCHO_PCICTRL_SBH_INT);
  709. psycho_write(base + PSYCHO_PCIA_CTRL, tmp);
  710. tmp = psycho_read(base + PSYCHO_PCIB_CTRL);
  711. tmp |= (PSYCHO_PCICTRL_SERR |
  712. PSYCHO_PCICTRL_SBH_ERR |
  713. PSYCHO_PCICTRL_EEN);
  714. tmp &= ~(PSYCHO_PCICTRL_SBH_INT);
  715. psycho_write(base + PSYCHO_PCIB_CTRL, tmp);
  716. }
  717. /* PSYCHO boot time probing and initialization. */
  718. static void pbm_config_busmastering(struct pci_pbm_info *pbm)
  719. {
  720. u8 *addr;
  721. /* Set cache-line size to 64 bytes, this is actually
  722. * a nop but I do it for completeness.
  723. */
  724. addr = psycho_pci_config_mkaddr(pbm, pbm->pci_first_busno,
  725. 0, PCI_CACHE_LINE_SIZE);
  726. pci_config_write8(addr, 64 / sizeof(u32));
  727. /* Set PBM latency timer to 64 PCI clocks. */
  728. addr = psycho_pci_config_mkaddr(pbm, pbm->pci_first_busno,
  729. 0, PCI_LATENCY_TIMER);
  730. pci_config_write8(addr, 64);
  731. }
  732. static void __init psycho_scan_bus(struct pci_pbm_info *pbm)
  733. {
  734. pbm_config_busmastering(pbm);
  735. pbm->is_66mhz_capable = 0;
  736. pbm->pci_bus = pci_scan_one_pbm(pbm);
  737. /* After the PCI bus scan is complete, we can register
  738. * the error interrupt handlers.
  739. */
  740. psycho_register_error_handlers(pbm);
  741. }
  742. static int psycho_iommu_init(struct pci_pbm_info *pbm)
  743. {
  744. struct iommu *iommu = pbm->iommu;
  745. unsigned long i;
  746. u64 control;
  747. int err;
  748. /* Register addresses. */
  749. iommu->iommu_control = pbm->controller_regs + PSYCHO_IOMMU_CONTROL;
  750. iommu->iommu_tsbbase = pbm->controller_regs + PSYCHO_IOMMU_TSBBASE;
  751. iommu->iommu_flush = pbm->controller_regs + PSYCHO_IOMMU_FLUSH;
  752. iommu->iommu_tags = iommu->iommu_flush + (0xa580UL - 0x0210UL);
  753. /* PSYCHO's IOMMU lacks ctx flushing. */
  754. iommu->iommu_ctxflush = 0;
  755. /* We use the main control register of PSYCHO as the write
  756. * completion register.
  757. */
  758. iommu->write_complete_reg = pbm->controller_regs + PSYCHO_CONTROL;
  759. /*
  760. * Invalidate TLB Entries.
  761. */
  762. control = psycho_read(pbm->controller_regs + PSYCHO_IOMMU_CONTROL);
  763. control |= PSYCHO_IOMMU_CTRL_DENAB;
  764. psycho_write(pbm->controller_regs + PSYCHO_IOMMU_CONTROL, control);
  765. for(i = 0; i < 16; i++) {
  766. psycho_write(pbm->controller_regs + PSYCHO_IOMMU_TAG + (i * 8UL), 0);
  767. psycho_write(pbm->controller_regs + PSYCHO_IOMMU_DATA + (i * 8UL), 0);
  768. }
  769. /* Leave diag mode enabled for full-flushing done
  770. * in pci_iommu.c
  771. */
  772. err = iommu_table_init(iommu, IO_TSB_SIZE, 0xc0000000, 0xffffffff,
  773. pbm->numa_node);
  774. if (err)
  775. return err;
  776. psycho_write(pbm->controller_regs + PSYCHO_IOMMU_TSBBASE,
  777. __pa(iommu->page_table));
  778. control = psycho_read(pbm->controller_regs + PSYCHO_IOMMU_CONTROL);
  779. control &= ~(PSYCHO_IOMMU_CTRL_TSBSZ | PSYCHO_IOMMU_CTRL_TBWSZ);
  780. control |= (PSYCHO_IOMMU_TSBSZ_128K | PSYCHO_IOMMU_CTRL_ENAB);
  781. psycho_write(pbm->controller_regs + PSYCHO_IOMMU_CONTROL, control);
  782. /* If necessary, hook us up for starfire IRQ translations. */
  783. if (this_is_starfire)
  784. starfire_hookup(pbm->portid);
  785. return 0;
  786. }
  787. #define PSYCHO_IRQ_RETRY 0x1a00UL
  788. #define PSYCHO_PCIA_DIAG 0x2020UL
  789. #define PSYCHO_PCIB_DIAG 0x4020UL
  790. #define PSYCHO_PCIDIAG_RESV 0xffffffffffffff80UL /* Reserved */
  791. #define PSYCHO_PCIDIAG_DRETRY 0x0000000000000040UL /* Disable retry limit */
  792. #define PSYCHO_PCIDIAG_DISYNC 0x0000000000000020UL /* Disable DMA wr / irq sync */
  793. #define PSYCHO_PCIDIAG_DDWSYNC 0x0000000000000010UL /* Disable DMA wr / PIO rd sync */
  794. #define PSYCHO_PCIDIAG_IDDPAR 0x0000000000000008UL /* Invert DMA data parity */
  795. #define PSYCHO_PCIDIAG_IPDPAR 0x0000000000000004UL /* Invert PIO data parity */
  796. #define PSYCHO_PCIDIAG_IPAPAR 0x0000000000000002UL /* Invert PIO address parity */
  797. #define PSYCHO_PCIDIAG_LPBACK 0x0000000000000001UL /* Enable loopback mode */
  798. static void psycho_controller_hwinit(struct pci_pbm_info *pbm)
  799. {
  800. u64 tmp;
  801. psycho_write(pbm->controller_regs + PSYCHO_IRQ_RETRY, 5);
  802. /* Enable arbiter for all PCI slots. */
  803. tmp = psycho_read(pbm->controller_regs + PSYCHO_PCIA_CTRL);
  804. tmp |= PSYCHO_PCICTRL_AEN;
  805. psycho_write(pbm->controller_regs + PSYCHO_PCIA_CTRL, tmp);
  806. tmp = psycho_read(pbm->controller_regs + PSYCHO_PCIB_CTRL);
  807. tmp |= PSYCHO_PCICTRL_AEN;
  808. psycho_write(pbm->controller_regs + PSYCHO_PCIB_CTRL, tmp);
  809. /* Disable DMA write / PIO read synchronization on
  810. * both PCI bus segments.
  811. * [ U2P Erratum 1243770, STP2223BGA data sheet ]
  812. */
  813. tmp = psycho_read(pbm->controller_regs + PSYCHO_PCIA_DIAG);
  814. tmp |= PSYCHO_PCIDIAG_DDWSYNC;
  815. psycho_write(pbm->controller_regs + PSYCHO_PCIA_DIAG, tmp);
  816. tmp = psycho_read(pbm->controller_regs + PSYCHO_PCIB_DIAG);
  817. tmp |= PSYCHO_PCIDIAG_DDWSYNC;
  818. psycho_write(pbm->controller_regs + PSYCHO_PCIB_DIAG, tmp);
  819. }
  820. static void psycho_pbm_strbuf_init(struct pci_pbm_info *pbm,
  821. int is_pbm_a)
  822. {
  823. unsigned long base = pbm->controller_regs;
  824. u64 control;
  825. if (is_pbm_a) {
  826. pbm->stc.strbuf_control = base + PSYCHO_STRBUF_CONTROL_A;
  827. pbm->stc.strbuf_pflush = base + PSYCHO_STRBUF_FLUSH_A;
  828. pbm->stc.strbuf_fsync = base + PSYCHO_STRBUF_FSYNC_A;
  829. } else {
  830. pbm->stc.strbuf_control = base + PSYCHO_STRBUF_CONTROL_B;
  831. pbm->stc.strbuf_pflush = base + PSYCHO_STRBUF_FLUSH_B;
  832. pbm->stc.strbuf_fsync = base + PSYCHO_STRBUF_FSYNC_B;
  833. }
  834. /* PSYCHO's streaming buffer lacks ctx flushing. */
  835. pbm->stc.strbuf_ctxflush = 0;
  836. pbm->stc.strbuf_ctxmatch_base = 0;
  837. pbm->stc.strbuf_flushflag = (volatile unsigned long *)
  838. ((((unsigned long)&pbm->stc.__flushflag_buf[0])
  839. + 63UL)
  840. & ~63UL);
  841. pbm->stc.strbuf_flushflag_pa = (unsigned long)
  842. __pa(pbm->stc.strbuf_flushflag);
  843. /* Enable the streaming buffer. We have to be careful
  844. * just in case OBP left it with LRU locking enabled.
  845. *
  846. * It is possible to control if PBM will be rerun on
  847. * line misses. Currently I just retain whatever setting
  848. * OBP left us with. All checks so far show it having
  849. * a value of zero.
  850. */
  851. #undef PSYCHO_STRBUF_RERUN_ENABLE
  852. #undef PSYCHO_STRBUF_RERUN_DISABLE
  853. control = psycho_read(pbm->stc.strbuf_control);
  854. control |= PSYCHO_STRBUF_CTRL_ENAB;
  855. control &= ~(PSYCHO_STRBUF_CTRL_LENAB | PSYCHO_STRBUF_CTRL_LPTR);
  856. #ifdef PSYCHO_STRBUF_RERUN_ENABLE
  857. control &= ~(PSYCHO_STRBUF_CTRL_RRDIS);
  858. #else
  859. #ifdef PSYCHO_STRBUF_RERUN_DISABLE
  860. control |= PSYCHO_STRBUF_CTRL_RRDIS;
  861. #endif
  862. #endif
  863. psycho_write(pbm->stc.strbuf_control, control);
  864. pbm->stc.strbuf_enabled = 1;
  865. }
  866. #define PSYCHO_IOSPACE_A 0x002000000UL
  867. #define PSYCHO_IOSPACE_B 0x002010000UL
  868. #define PSYCHO_IOSPACE_SIZE 0x00000ffffUL
  869. #define PSYCHO_MEMSPACE_A 0x100000000UL
  870. #define PSYCHO_MEMSPACE_B 0x180000000UL
  871. #define PSYCHO_MEMSPACE_SIZE 0x07fffffffUL
  872. static void __init psycho_pbm_init(struct pci_controller_info *p,
  873. struct device_node *dp, int is_pbm_a)
  874. {
  875. struct property *prop;
  876. struct pci_pbm_info *pbm;
  877. if (is_pbm_a)
  878. pbm = &p->pbm_A;
  879. else
  880. pbm = &p->pbm_B;
  881. pbm->next = pci_pbm_root;
  882. pci_pbm_root = pbm;
  883. pbm->numa_node = -1;
  884. pbm->scan_bus = psycho_scan_bus;
  885. pbm->pci_ops = &sun4u_pci_ops;
  886. pbm->config_space_reg_bits = 8;
  887. pbm->index = pci_num_pbms++;
  888. pbm->chip_type = PBM_CHIP_TYPE_PSYCHO;
  889. pbm->chip_version = 0;
  890. prop = of_find_property(dp, "version#", NULL);
  891. if (prop)
  892. pbm->chip_version = *(int *) prop->value;
  893. pbm->chip_revision = 0;
  894. prop = of_find_property(dp, "module-revision#", NULL);
  895. if (prop)
  896. pbm->chip_revision = *(int *) prop->value;
  897. pbm->parent = p;
  898. pbm->prom_node = dp;
  899. pbm->name = dp->full_name;
  900. printk("%s: PSYCHO PCI Bus Module ver[%x:%x]\n",
  901. pbm->name,
  902. pbm->chip_version, pbm->chip_revision);
  903. pci_determine_mem_io_space(pbm);
  904. pci_get_pbm_props(pbm);
  905. psycho_pbm_strbuf_init(pbm, is_pbm_a);
  906. }
  907. #define PSYCHO_CONFIGSPACE 0x001000000UL
  908. void __init psycho_init(struct device_node *dp, char *model_name)
  909. {
  910. struct linux_prom64_registers *pr_regs;
  911. struct pci_controller_info *p;
  912. struct pci_pbm_info *pbm;
  913. struct iommu *iommu;
  914. struct property *prop;
  915. u32 upa_portid;
  916. int is_pbm_a;
  917. upa_portid = 0xff;
  918. prop = of_find_property(dp, "upa-portid", NULL);
  919. if (prop)
  920. upa_portid = *(u32 *) prop->value;
  921. for (pbm = pci_pbm_root; pbm; pbm = pbm->next) {
  922. struct pci_controller_info *p = pbm->parent;
  923. if (p->pbm_A.portid == upa_portid) {
  924. is_pbm_a = (p->pbm_A.prom_node == NULL);
  925. psycho_pbm_init(p, dp, is_pbm_a);
  926. return;
  927. }
  928. }
  929. p = kzalloc(sizeof(struct pci_controller_info), GFP_ATOMIC);
  930. if (!p)
  931. goto fatal_memory_error;
  932. iommu = kzalloc(sizeof(struct iommu), GFP_ATOMIC);
  933. if (!iommu)
  934. goto fatal_memory_error;
  935. p->pbm_A.iommu = p->pbm_B.iommu = iommu;
  936. p->pbm_A.portid = upa_portid;
  937. p->pbm_B.portid = upa_portid;
  938. prop = of_find_property(dp, "reg", NULL);
  939. pr_regs = prop->value;
  940. p->pbm_A.controller_regs = pr_regs[2].phys_addr;
  941. p->pbm_B.controller_regs = pr_regs[2].phys_addr;
  942. p->pbm_A.config_space = p->pbm_B.config_space =
  943. (pr_regs[2].phys_addr + PSYCHO_CONFIGSPACE);
  944. psycho_controller_hwinit(&p->pbm_A);
  945. if (psycho_iommu_init(&p->pbm_A))
  946. goto fatal_memory_error;
  947. is_pbm_a = ((pr_regs[0].phys_addr & 0x6000) == 0x2000);
  948. psycho_pbm_init(p, dp, is_pbm_a);
  949. return;
  950. fatal_memory_error:
  951. prom_printf("PSYCHO: Fatal memory allocation error.\n");
  952. prom_halt();
  953. }