sbus.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. /*
  2. * sbus.c: UltraSparc SBUS controller support.
  3. *
  4. * Copyright (C) 1999 David S. Miller (davem@redhat.com)
  5. */
  6. #include <linux/kernel.h>
  7. #include <linux/types.h>
  8. #include <linux/mm.h>
  9. #include <linux/spinlock.h>
  10. #include <linux/slab.h>
  11. #include <linux/init.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/of.h>
  14. #include <linux/of_device.h>
  15. #include <asm/page.h>
  16. #include <asm/io.h>
  17. #include <asm/upa.h>
  18. #include <asm/cache.h>
  19. #include <asm/dma.h>
  20. #include <asm/irq.h>
  21. #include <asm/prom.h>
  22. #include <asm/oplib.h>
  23. #include <asm/starfire.h>
  24. #include "iommu_common.h"
  25. #define MAP_BASE ((u32)0xc0000000)
  26. /* Offsets from iommu_regs */
  27. #define SYSIO_IOMMUREG_BASE 0x2400UL
  28. #define IOMMU_CONTROL (0x2400UL - 0x2400UL) /* IOMMU control register */
  29. #define IOMMU_TSBBASE (0x2408UL - 0x2400UL) /* TSB base address register */
  30. #define IOMMU_FLUSH (0x2410UL - 0x2400UL) /* IOMMU flush register */
  31. #define IOMMU_VADIAG (0x4400UL - 0x2400UL) /* SBUS virtual address diagnostic */
  32. #define IOMMU_TAGCMP (0x4408UL - 0x2400UL) /* TLB tag compare diagnostics */
  33. #define IOMMU_LRUDIAG (0x4500UL - 0x2400UL) /* IOMMU LRU queue diagnostics */
  34. #define IOMMU_TAGDIAG (0x4580UL - 0x2400UL) /* TLB tag diagnostics */
  35. #define IOMMU_DRAMDIAG (0x4600UL - 0x2400UL) /* TLB data RAM diagnostics */
  36. #define IOMMU_DRAM_VALID (1UL << 30UL)
  37. /* Offsets from strbuf_regs */
  38. #define SYSIO_STRBUFREG_BASE 0x2800UL
  39. #define STRBUF_CONTROL (0x2800UL - 0x2800UL) /* Control */
  40. #define STRBUF_PFLUSH (0x2808UL - 0x2800UL) /* Page flush/invalidate */
  41. #define STRBUF_FSYNC (0x2810UL - 0x2800UL) /* Flush synchronization */
  42. #define STRBUF_DRAMDIAG (0x5000UL - 0x2800UL) /* data RAM diagnostic */
  43. #define STRBUF_ERRDIAG (0x5400UL - 0x2800UL) /* error status diagnostics */
  44. #define STRBUF_PTAGDIAG (0x5800UL - 0x2800UL) /* Page tag diagnostics */
  45. #define STRBUF_LTAGDIAG (0x5900UL - 0x2800UL) /* Line tag diagnostics */
  46. #define STRBUF_TAG_VALID 0x02UL
  47. /* Enable 64-bit DVMA mode for the given device. */
  48. void sbus_set_sbus64(struct device *dev, int bursts)
  49. {
  50. struct iommu *iommu = dev->archdata.iommu;
  51. struct of_device *op = to_of_device(dev);
  52. const struct linux_prom_registers *regs;
  53. unsigned long cfg_reg;
  54. int slot;
  55. u64 val;
  56. regs = of_get_property(op->node, "reg", NULL);
  57. if (!regs) {
  58. printk(KERN_ERR "sbus_set_sbus64: Cannot find regs for %s\n",
  59. op->node->full_name);
  60. return;
  61. }
  62. slot = regs->which_io;
  63. cfg_reg = iommu->write_complete_reg;
  64. switch (slot) {
  65. case 0:
  66. cfg_reg += 0x20UL;
  67. break;
  68. case 1:
  69. cfg_reg += 0x28UL;
  70. break;
  71. case 2:
  72. cfg_reg += 0x30UL;
  73. break;
  74. case 3:
  75. cfg_reg += 0x38UL;
  76. break;
  77. case 13:
  78. cfg_reg += 0x40UL;
  79. break;
  80. case 14:
  81. cfg_reg += 0x48UL;
  82. break;
  83. case 15:
  84. cfg_reg += 0x50UL;
  85. break;
  86. default:
  87. return;
  88. };
  89. val = upa_readq(cfg_reg);
  90. if (val & (1UL << 14UL)) {
  91. /* Extended transfer mode already enabled. */
  92. return;
  93. }
  94. val |= (1UL << 14UL);
  95. if (bursts & DMA_BURST8)
  96. val |= (1UL << 1UL);
  97. if (bursts & DMA_BURST16)
  98. val |= (1UL << 2UL);
  99. if (bursts & DMA_BURST32)
  100. val |= (1UL << 3UL);
  101. if (bursts & DMA_BURST64)
  102. val |= (1UL << 4UL);
  103. upa_writeq(val, cfg_reg);
  104. }
  105. /* INO number to IMAP register offset for SYSIO external IRQ's.
  106. * This should conform to both Sunfire/Wildfire server and Fusion
  107. * desktop designs.
  108. */
  109. #define SYSIO_IMAP_SLOT0 0x2c00UL
  110. #define SYSIO_IMAP_SLOT1 0x2c08UL
  111. #define SYSIO_IMAP_SLOT2 0x2c10UL
  112. #define SYSIO_IMAP_SLOT3 0x2c18UL
  113. #define SYSIO_IMAP_SCSI 0x3000UL
  114. #define SYSIO_IMAP_ETH 0x3008UL
  115. #define SYSIO_IMAP_BPP 0x3010UL
  116. #define SYSIO_IMAP_AUDIO 0x3018UL
  117. #define SYSIO_IMAP_PFAIL 0x3020UL
  118. #define SYSIO_IMAP_KMS 0x3028UL
  119. #define SYSIO_IMAP_FLPY 0x3030UL
  120. #define SYSIO_IMAP_SHW 0x3038UL
  121. #define SYSIO_IMAP_KBD 0x3040UL
  122. #define SYSIO_IMAP_MS 0x3048UL
  123. #define SYSIO_IMAP_SER 0x3050UL
  124. #define SYSIO_IMAP_TIM0 0x3060UL
  125. #define SYSIO_IMAP_TIM1 0x3068UL
  126. #define SYSIO_IMAP_UE 0x3070UL
  127. #define SYSIO_IMAP_CE 0x3078UL
  128. #define SYSIO_IMAP_SBERR 0x3080UL
  129. #define SYSIO_IMAP_PMGMT 0x3088UL
  130. #define SYSIO_IMAP_GFX 0x3090UL
  131. #define SYSIO_IMAP_EUPA 0x3098UL
  132. #define bogon ((unsigned long) -1)
  133. static unsigned long sysio_irq_offsets[] = {
  134. /* SBUS Slot 0 --> 3, level 1 --> 7 */
  135. SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0,
  136. SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0,
  137. SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1,
  138. SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1,
  139. SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2,
  140. SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2,
  141. SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3,
  142. SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3,
  143. /* Onboard devices (not relevant/used on SunFire). */
  144. SYSIO_IMAP_SCSI,
  145. SYSIO_IMAP_ETH,
  146. SYSIO_IMAP_BPP,
  147. bogon,
  148. SYSIO_IMAP_AUDIO,
  149. SYSIO_IMAP_PFAIL,
  150. bogon,
  151. bogon,
  152. SYSIO_IMAP_KMS,
  153. SYSIO_IMAP_FLPY,
  154. SYSIO_IMAP_SHW,
  155. SYSIO_IMAP_KBD,
  156. SYSIO_IMAP_MS,
  157. SYSIO_IMAP_SER,
  158. bogon,
  159. bogon,
  160. SYSIO_IMAP_TIM0,
  161. SYSIO_IMAP_TIM1,
  162. bogon,
  163. bogon,
  164. SYSIO_IMAP_UE,
  165. SYSIO_IMAP_CE,
  166. SYSIO_IMAP_SBERR,
  167. SYSIO_IMAP_PMGMT,
  168. };
  169. #undef bogon
  170. #define NUM_SYSIO_OFFSETS ARRAY_SIZE(sysio_irq_offsets)
  171. /* Convert Interrupt Mapping register pointer to associated
  172. * Interrupt Clear register pointer, SYSIO specific version.
  173. */
  174. #define SYSIO_ICLR_UNUSED0 0x3400UL
  175. #define SYSIO_ICLR_SLOT0 0x3408UL
  176. #define SYSIO_ICLR_SLOT1 0x3448UL
  177. #define SYSIO_ICLR_SLOT2 0x3488UL
  178. #define SYSIO_ICLR_SLOT3 0x34c8UL
  179. static unsigned long sysio_imap_to_iclr(unsigned long imap)
  180. {
  181. unsigned long diff = SYSIO_ICLR_UNUSED0 - SYSIO_IMAP_SLOT0;
  182. return imap + diff;
  183. }
  184. static unsigned int sbus_build_irq(struct of_device *op, unsigned int ino)
  185. {
  186. struct iommu *iommu = op->dev.archdata.iommu;
  187. unsigned long reg_base = iommu->write_complete_reg - 0x2000UL;
  188. unsigned long imap, iclr;
  189. int sbus_level = 0;
  190. imap = sysio_irq_offsets[ino];
  191. if (imap == ((unsigned long)-1)) {
  192. prom_printf("get_irq_translations: Bad SYSIO INO[%x]\n",
  193. ino);
  194. prom_halt();
  195. }
  196. imap += reg_base;
  197. /* SYSIO inconsistency. For external SLOTS, we have to select
  198. * the right ICLR register based upon the lower SBUS irq level
  199. * bits.
  200. */
  201. if (ino >= 0x20) {
  202. iclr = sysio_imap_to_iclr(imap);
  203. } else {
  204. int sbus_slot = (ino & 0x18)>>3;
  205. sbus_level = ino & 0x7;
  206. switch(sbus_slot) {
  207. case 0:
  208. iclr = reg_base + SYSIO_ICLR_SLOT0;
  209. break;
  210. case 1:
  211. iclr = reg_base + SYSIO_ICLR_SLOT1;
  212. break;
  213. case 2:
  214. iclr = reg_base + SYSIO_ICLR_SLOT2;
  215. break;
  216. default:
  217. case 3:
  218. iclr = reg_base + SYSIO_ICLR_SLOT3;
  219. break;
  220. };
  221. iclr += ((unsigned long)sbus_level - 1UL) * 8UL;
  222. }
  223. return build_irq(sbus_level, iclr, imap);
  224. }
  225. /* Error interrupt handling. */
  226. #define SYSIO_UE_AFSR 0x0030UL
  227. #define SYSIO_UE_AFAR 0x0038UL
  228. #define SYSIO_UEAFSR_PPIO 0x8000000000000000UL /* Primary PIO cause */
  229. #define SYSIO_UEAFSR_PDRD 0x4000000000000000UL /* Primary DVMA read cause */
  230. #define SYSIO_UEAFSR_PDWR 0x2000000000000000UL /* Primary DVMA write cause */
  231. #define SYSIO_UEAFSR_SPIO 0x1000000000000000UL /* Secondary PIO is cause */
  232. #define SYSIO_UEAFSR_SDRD 0x0800000000000000UL /* Secondary DVMA read cause */
  233. #define SYSIO_UEAFSR_SDWR 0x0400000000000000UL /* Secondary DVMA write cause*/
  234. #define SYSIO_UEAFSR_RESV1 0x03ff000000000000UL /* Reserved */
  235. #define SYSIO_UEAFSR_DOFF 0x0000e00000000000UL /* Doubleword Offset */
  236. #define SYSIO_UEAFSR_SIZE 0x00001c0000000000UL /* Bad transfer size 2^SIZE */
  237. #define SYSIO_UEAFSR_MID 0x000003e000000000UL /* UPA MID causing the fault */
  238. #define SYSIO_UEAFSR_RESV2 0x0000001fffffffffUL /* Reserved */
  239. static irqreturn_t sysio_ue_handler(int irq, void *dev_id)
  240. {
  241. struct of_device *op = dev_id;
  242. struct iommu *iommu = op->dev.archdata.iommu;
  243. unsigned long reg_base = iommu->write_complete_reg - 0x2000UL;
  244. unsigned long afsr_reg, afar_reg;
  245. unsigned long afsr, afar, error_bits;
  246. int reported, portid;
  247. afsr_reg = reg_base + SYSIO_UE_AFSR;
  248. afar_reg = reg_base + SYSIO_UE_AFAR;
  249. /* Latch error status. */
  250. afsr = upa_readq(afsr_reg);
  251. afar = upa_readq(afar_reg);
  252. /* Clear primary/secondary error status bits. */
  253. error_bits = afsr &
  254. (SYSIO_UEAFSR_PPIO | SYSIO_UEAFSR_PDRD | SYSIO_UEAFSR_PDWR |
  255. SYSIO_UEAFSR_SPIO | SYSIO_UEAFSR_SDRD | SYSIO_UEAFSR_SDWR);
  256. upa_writeq(error_bits, afsr_reg);
  257. portid = of_getintprop_default(op->node, "portid", -1);
  258. /* Log the error. */
  259. printk("SYSIO[%x]: Uncorrectable ECC Error, primary error type[%s]\n",
  260. portid,
  261. (((error_bits & SYSIO_UEAFSR_PPIO) ?
  262. "PIO" :
  263. ((error_bits & SYSIO_UEAFSR_PDRD) ?
  264. "DVMA Read" :
  265. ((error_bits & SYSIO_UEAFSR_PDWR) ?
  266. "DVMA Write" : "???")))));
  267. printk("SYSIO[%x]: DOFF[%lx] SIZE[%lx] MID[%lx]\n",
  268. portid,
  269. (afsr & SYSIO_UEAFSR_DOFF) >> 45UL,
  270. (afsr & SYSIO_UEAFSR_SIZE) >> 42UL,
  271. (afsr & SYSIO_UEAFSR_MID) >> 37UL);
  272. printk("SYSIO[%x]: AFAR[%016lx]\n", portid, afar);
  273. printk("SYSIO[%x]: Secondary UE errors [", portid);
  274. reported = 0;
  275. if (afsr & SYSIO_UEAFSR_SPIO) {
  276. reported++;
  277. printk("(PIO)");
  278. }
  279. if (afsr & SYSIO_UEAFSR_SDRD) {
  280. reported++;
  281. printk("(DVMA Read)");
  282. }
  283. if (afsr & SYSIO_UEAFSR_SDWR) {
  284. reported++;
  285. printk("(DVMA Write)");
  286. }
  287. if (!reported)
  288. printk("(none)");
  289. printk("]\n");
  290. return IRQ_HANDLED;
  291. }
  292. #define SYSIO_CE_AFSR 0x0040UL
  293. #define SYSIO_CE_AFAR 0x0048UL
  294. #define SYSIO_CEAFSR_PPIO 0x8000000000000000UL /* Primary PIO cause */
  295. #define SYSIO_CEAFSR_PDRD 0x4000000000000000UL /* Primary DVMA read cause */
  296. #define SYSIO_CEAFSR_PDWR 0x2000000000000000UL /* Primary DVMA write cause */
  297. #define SYSIO_CEAFSR_SPIO 0x1000000000000000UL /* Secondary PIO cause */
  298. #define SYSIO_CEAFSR_SDRD 0x0800000000000000UL /* Secondary DVMA read cause */
  299. #define SYSIO_CEAFSR_SDWR 0x0400000000000000UL /* Secondary DVMA write cause*/
  300. #define SYSIO_CEAFSR_RESV1 0x0300000000000000UL /* Reserved */
  301. #define SYSIO_CEAFSR_ESYND 0x00ff000000000000UL /* Syndrome Bits */
  302. #define SYSIO_CEAFSR_DOFF 0x0000e00000000000UL /* Double Offset */
  303. #define SYSIO_CEAFSR_SIZE 0x00001c0000000000UL /* Bad transfer size 2^SIZE */
  304. #define SYSIO_CEAFSR_MID 0x000003e000000000UL /* UPA MID causing the fault */
  305. #define SYSIO_CEAFSR_RESV2 0x0000001fffffffffUL /* Reserved */
  306. static irqreturn_t sysio_ce_handler(int irq, void *dev_id)
  307. {
  308. struct of_device *op = dev_id;
  309. struct iommu *iommu = op->dev.archdata.iommu;
  310. unsigned long reg_base = iommu->write_complete_reg - 0x2000UL;
  311. unsigned long afsr_reg, afar_reg;
  312. unsigned long afsr, afar, error_bits;
  313. int reported, portid;
  314. afsr_reg = reg_base + SYSIO_CE_AFSR;
  315. afar_reg = reg_base + SYSIO_CE_AFAR;
  316. /* Latch error status. */
  317. afsr = upa_readq(afsr_reg);
  318. afar = upa_readq(afar_reg);
  319. /* Clear primary/secondary error status bits. */
  320. error_bits = afsr &
  321. (SYSIO_CEAFSR_PPIO | SYSIO_CEAFSR_PDRD | SYSIO_CEAFSR_PDWR |
  322. SYSIO_CEAFSR_SPIO | SYSIO_CEAFSR_SDRD | SYSIO_CEAFSR_SDWR);
  323. upa_writeq(error_bits, afsr_reg);
  324. portid = of_getintprop_default(op->node, "portid", -1);
  325. printk("SYSIO[%x]: Correctable ECC Error, primary error type[%s]\n",
  326. portid,
  327. (((error_bits & SYSIO_CEAFSR_PPIO) ?
  328. "PIO" :
  329. ((error_bits & SYSIO_CEAFSR_PDRD) ?
  330. "DVMA Read" :
  331. ((error_bits & SYSIO_CEAFSR_PDWR) ?
  332. "DVMA Write" : "???")))));
  333. /* XXX Use syndrome and afar to print out module string just like
  334. * XXX UDB CE trap handler does... -DaveM
  335. */
  336. printk("SYSIO[%x]: DOFF[%lx] ECC Syndrome[%lx] Size[%lx] MID[%lx]\n",
  337. portid,
  338. (afsr & SYSIO_CEAFSR_DOFF) >> 45UL,
  339. (afsr & SYSIO_CEAFSR_ESYND) >> 48UL,
  340. (afsr & SYSIO_CEAFSR_SIZE) >> 42UL,
  341. (afsr & SYSIO_CEAFSR_MID) >> 37UL);
  342. printk("SYSIO[%x]: AFAR[%016lx]\n", portid, afar);
  343. printk("SYSIO[%x]: Secondary CE errors [", portid);
  344. reported = 0;
  345. if (afsr & SYSIO_CEAFSR_SPIO) {
  346. reported++;
  347. printk("(PIO)");
  348. }
  349. if (afsr & SYSIO_CEAFSR_SDRD) {
  350. reported++;
  351. printk("(DVMA Read)");
  352. }
  353. if (afsr & SYSIO_CEAFSR_SDWR) {
  354. reported++;
  355. printk("(DVMA Write)");
  356. }
  357. if (!reported)
  358. printk("(none)");
  359. printk("]\n");
  360. return IRQ_HANDLED;
  361. }
  362. #define SYSIO_SBUS_AFSR 0x2010UL
  363. #define SYSIO_SBUS_AFAR 0x2018UL
  364. #define SYSIO_SBAFSR_PLE 0x8000000000000000UL /* Primary Late PIO Error */
  365. #define SYSIO_SBAFSR_PTO 0x4000000000000000UL /* Primary SBUS Timeout */
  366. #define SYSIO_SBAFSR_PBERR 0x2000000000000000UL /* Primary SBUS Error ACK */
  367. #define SYSIO_SBAFSR_SLE 0x1000000000000000UL /* Secondary Late PIO Error */
  368. #define SYSIO_SBAFSR_STO 0x0800000000000000UL /* Secondary SBUS Timeout */
  369. #define SYSIO_SBAFSR_SBERR 0x0400000000000000UL /* Secondary SBUS Error ACK */
  370. #define SYSIO_SBAFSR_RESV1 0x03ff000000000000UL /* Reserved */
  371. #define SYSIO_SBAFSR_RD 0x0000800000000000UL /* Primary was late PIO read */
  372. #define SYSIO_SBAFSR_RESV2 0x0000600000000000UL /* Reserved */
  373. #define SYSIO_SBAFSR_SIZE 0x00001c0000000000UL /* Size of transfer */
  374. #define SYSIO_SBAFSR_MID 0x000003e000000000UL /* MID causing the error */
  375. #define SYSIO_SBAFSR_RESV3 0x0000001fffffffffUL /* Reserved */
  376. static irqreturn_t sysio_sbus_error_handler(int irq, void *dev_id)
  377. {
  378. struct of_device *op = dev_id;
  379. struct iommu *iommu = op->dev.archdata.iommu;
  380. unsigned long afsr_reg, afar_reg, reg_base;
  381. unsigned long afsr, afar, error_bits;
  382. int reported, portid;
  383. reg_base = iommu->write_complete_reg - 0x2000UL;
  384. afsr_reg = reg_base + SYSIO_SBUS_AFSR;
  385. afar_reg = reg_base + SYSIO_SBUS_AFAR;
  386. afsr = upa_readq(afsr_reg);
  387. afar = upa_readq(afar_reg);
  388. /* Clear primary/secondary error status bits. */
  389. error_bits = afsr &
  390. (SYSIO_SBAFSR_PLE | SYSIO_SBAFSR_PTO | SYSIO_SBAFSR_PBERR |
  391. SYSIO_SBAFSR_SLE | SYSIO_SBAFSR_STO | SYSIO_SBAFSR_SBERR);
  392. upa_writeq(error_bits, afsr_reg);
  393. portid = of_getintprop_default(op->node, "portid", -1);
  394. /* Log the error. */
  395. printk("SYSIO[%x]: SBUS Error, primary error type[%s] read(%d)\n",
  396. portid,
  397. (((error_bits & SYSIO_SBAFSR_PLE) ?
  398. "Late PIO Error" :
  399. ((error_bits & SYSIO_SBAFSR_PTO) ?
  400. "Time Out" :
  401. ((error_bits & SYSIO_SBAFSR_PBERR) ?
  402. "Error Ack" : "???")))),
  403. (afsr & SYSIO_SBAFSR_RD) ? 1 : 0);
  404. printk("SYSIO[%x]: size[%lx] MID[%lx]\n",
  405. portid,
  406. (afsr & SYSIO_SBAFSR_SIZE) >> 42UL,
  407. (afsr & SYSIO_SBAFSR_MID) >> 37UL);
  408. printk("SYSIO[%x]: AFAR[%016lx]\n", portid, afar);
  409. printk("SYSIO[%x]: Secondary SBUS errors [", portid);
  410. reported = 0;
  411. if (afsr & SYSIO_SBAFSR_SLE) {
  412. reported++;
  413. printk("(Late PIO Error)");
  414. }
  415. if (afsr & SYSIO_SBAFSR_STO) {
  416. reported++;
  417. printk("(Time Out)");
  418. }
  419. if (afsr & SYSIO_SBAFSR_SBERR) {
  420. reported++;
  421. printk("(Error Ack)");
  422. }
  423. if (!reported)
  424. printk("(none)");
  425. printk("]\n");
  426. /* XXX check iommu/strbuf for further error status XXX */
  427. return IRQ_HANDLED;
  428. }
  429. #define ECC_CONTROL 0x0020UL
  430. #define SYSIO_ECNTRL_ECCEN 0x8000000000000000UL /* Enable ECC Checking */
  431. #define SYSIO_ECNTRL_UEEN 0x4000000000000000UL /* Enable UE Interrupts */
  432. #define SYSIO_ECNTRL_CEEN 0x2000000000000000UL /* Enable CE Interrupts */
  433. #define SYSIO_UE_INO 0x34
  434. #define SYSIO_CE_INO 0x35
  435. #define SYSIO_SBUSERR_INO 0x36
  436. static void __init sysio_register_error_handlers(struct of_device *op)
  437. {
  438. struct iommu *iommu = op->dev.archdata.iommu;
  439. unsigned long reg_base = iommu->write_complete_reg - 0x2000UL;
  440. unsigned int irq;
  441. u64 control;
  442. int portid;
  443. portid = of_getintprop_default(op->node, "portid", -1);
  444. irq = sbus_build_irq(op, SYSIO_UE_INO);
  445. if (request_irq(irq, sysio_ue_handler, 0,
  446. "SYSIO_UE", op) < 0) {
  447. prom_printf("SYSIO[%x]: Cannot register UE interrupt.\n",
  448. portid);
  449. prom_halt();
  450. }
  451. irq = sbus_build_irq(op, SYSIO_CE_INO);
  452. if (request_irq(irq, sysio_ce_handler, 0,
  453. "SYSIO_CE", op) < 0) {
  454. prom_printf("SYSIO[%x]: Cannot register CE interrupt.\n",
  455. portid);
  456. prom_halt();
  457. }
  458. irq = sbus_build_irq(op, SYSIO_SBUSERR_INO);
  459. if (request_irq(irq, sysio_sbus_error_handler, 0,
  460. "SYSIO_SBERR", op) < 0) {
  461. prom_printf("SYSIO[%x]: Cannot register SBUS Error interrupt.\n",
  462. portid);
  463. prom_halt();
  464. }
  465. /* Now turn the error interrupts on and also enable ECC checking. */
  466. upa_writeq((SYSIO_ECNTRL_ECCEN |
  467. SYSIO_ECNTRL_UEEN |
  468. SYSIO_ECNTRL_CEEN),
  469. reg_base + ECC_CONTROL);
  470. control = upa_readq(iommu->write_complete_reg);
  471. control |= 0x100UL; /* SBUS Error Interrupt Enable */
  472. upa_writeq(control, iommu->write_complete_reg);
  473. }
  474. /* Boot time initialization. */
  475. static void __init sbus_iommu_init(struct of_device *op)
  476. {
  477. const struct linux_prom64_registers *pr;
  478. struct device_node *dp = op->node;
  479. struct iommu *iommu;
  480. struct strbuf *strbuf;
  481. unsigned long regs, reg_base;
  482. int i, portid;
  483. u64 control;
  484. pr = of_get_property(dp, "reg", NULL);
  485. if (!pr) {
  486. prom_printf("sbus_iommu_init: Cannot map SYSIO "
  487. "control registers.\n");
  488. prom_halt();
  489. }
  490. regs = pr->phys_addr;
  491. iommu = kzalloc(sizeof(*iommu), GFP_ATOMIC);
  492. if (!iommu)
  493. goto fatal_memory_error;
  494. strbuf = kzalloc(sizeof(*strbuf), GFP_ATOMIC);
  495. if (!strbuf)
  496. goto fatal_memory_error;
  497. op->dev.archdata.iommu = iommu;
  498. op->dev.archdata.stc = strbuf;
  499. op->dev.archdata.numa_node = -1;
  500. reg_base = regs + SYSIO_IOMMUREG_BASE;
  501. iommu->iommu_control = reg_base + IOMMU_CONTROL;
  502. iommu->iommu_tsbbase = reg_base + IOMMU_TSBBASE;
  503. iommu->iommu_flush = reg_base + IOMMU_FLUSH;
  504. iommu->iommu_tags = iommu->iommu_control +
  505. (IOMMU_TAGDIAG - IOMMU_CONTROL);
  506. reg_base = regs + SYSIO_STRBUFREG_BASE;
  507. strbuf->strbuf_control = reg_base + STRBUF_CONTROL;
  508. strbuf->strbuf_pflush = reg_base + STRBUF_PFLUSH;
  509. strbuf->strbuf_fsync = reg_base + STRBUF_FSYNC;
  510. strbuf->strbuf_enabled = 1;
  511. strbuf->strbuf_flushflag = (volatile unsigned long *)
  512. ((((unsigned long)&strbuf->__flushflag_buf[0])
  513. + 63UL)
  514. & ~63UL);
  515. strbuf->strbuf_flushflag_pa = (unsigned long)
  516. __pa(strbuf->strbuf_flushflag);
  517. /* The SYSIO SBUS control register is used for dummy reads
  518. * in order to ensure write completion.
  519. */
  520. iommu->write_complete_reg = regs + 0x2000UL;
  521. portid = of_getintprop_default(op->node, "portid", -1);
  522. printk(KERN_INFO "SYSIO: UPA portID %x, at %016lx\n",
  523. portid, regs);
  524. /* Setup for TSB_SIZE=7, TBW_SIZE=0, MMU_DE=1, MMU_EN=1 */
  525. if (iommu_table_init(iommu, IO_TSB_SIZE, MAP_BASE, 0xffffffff, -1))
  526. goto fatal_memory_error;
  527. control = upa_readq(iommu->iommu_control);
  528. control = ((7UL << 16UL) |
  529. (0UL << 2UL) |
  530. (1UL << 1UL) |
  531. (1UL << 0UL));
  532. upa_writeq(control, iommu->iommu_control);
  533. /* Clean out any cruft in the IOMMU using
  534. * diagnostic accesses.
  535. */
  536. for (i = 0; i < 16; i++) {
  537. unsigned long dram, tag;
  538. dram = iommu->iommu_control + (IOMMU_DRAMDIAG - IOMMU_CONTROL);
  539. tag = iommu->iommu_control + (IOMMU_TAGDIAG - IOMMU_CONTROL);
  540. dram += (unsigned long)i * 8UL;
  541. tag += (unsigned long)i * 8UL;
  542. upa_writeq(0, dram);
  543. upa_writeq(0, tag);
  544. }
  545. upa_readq(iommu->write_complete_reg);
  546. /* Give the TSB to SYSIO. */
  547. upa_writeq(__pa(iommu->page_table), iommu->iommu_tsbbase);
  548. /* Setup streaming buffer, DE=1 SB_EN=1 */
  549. control = (1UL << 1UL) | (1UL << 0UL);
  550. upa_writeq(control, strbuf->strbuf_control);
  551. /* Clear out the tags using diagnostics. */
  552. for (i = 0; i < 16; i++) {
  553. unsigned long ptag, ltag;
  554. ptag = strbuf->strbuf_control +
  555. (STRBUF_PTAGDIAG - STRBUF_CONTROL);
  556. ltag = strbuf->strbuf_control +
  557. (STRBUF_LTAGDIAG - STRBUF_CONTROL);
  558. ptag += (unsigned long)i * 8UL;
  559. ltag += (unsigned long)i * 8UL;
  560. upa_writeq(0UL, ptag);
  561. upa_writeq(0UL, ltag);
  562. }
  563. /* Enable DVMA arbitration for all devices/slots. */
  564. control = upa_readq(iommu->write_complete_reg);
  565. control |= 0x3fUL;
  566. upa_writeq(control, iommu->write_complete_reg);
  567. /* Now some Xfire specific grot... */
  568. if (this_is_starfire)
  569. starfire_hookup(portid);
  570. sysio_register_error_handlers(op);
  571. return;
  572. fatal_memory_error:
  573. prom_printf("sbus_iommu_init: Fatal memory allocation error.\n");
  574. }
  575. static int __init sbus_init(void)
  576. {
  577. struct device_node *dp;
  578. for_each_node_by_name(dp, "sbus") {
  579. struct of_device *op = of_find_device_by_node(dp);
  580. sbus_iommu_init(op);
  581. of_propagate_archdata(op);
  582. }
  583. return 0;
  584. }
  585. subsys_initcall(sbus_init);