sbus.c 20 KB

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