pci_psycho.c 38 KB

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