pci_psycho.c 40 KB

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