pci_psycho.c 37 KB

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