pci_psycho.c 43 KB

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