sbus.c 20 KB

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