sbus.c 20 KB

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