pci_psycho.c 35 KB

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