sbus.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170
  1. /* $Id: sbus.c,v 1.19 2002/01/23 11:27:32 davem Exp $
  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. struct sbus_iommu {
  25. spinlock_t lock;
  26. struct iommu_arena arena;
  27. iopte_t *page_table;
  28. unsigned long strbuf_regs;
  29. unsigned long iommu_regs;
  30. unsigned long sbus_control_reg;
  31. volatile unsigned long strbuf_flushflag;
  32. };
  33. /* Offsets from iommu_regs */
  34. #define SYSIO_IOMMUREG_BASE 0x2400UL
  35. #define IOMMU_CONTROL (0x2400UL - 0x2400UL) /* IOMMU control register */
  36. #define IOMMU_TSBBASE (0x2408UL - 0x2400UL) /* TSB base address register */
  37. #define IOMMU_FLUSH (0x2410UL - 0x2400UL) /* IOMMU flush register */
  38. #define IOMMU_VADIAG (0x4400UL - 0x2400UL) /* SBUS virtual address diagnostic */
  39. #define IOMMU_TAGCMP (0x4408UL - 0x2400UL) /* TLB tag compare diagnostics */
  40. #define IOMMU_LRUDIAG (0x4500UL - 0x2400UL) /* IOMMU LRU queue diagnostics */
  41. #define IOMMU_TAGDIAG (0x4580UL - 0x2400UL) /* TLB tag diagnostics */
  42. #define IOMMU_DRAMDIAG (0x4600UL - 0x2400UL) /* TLB data RAM diagnostics */
  43. #define IOMMU_DRAM_VALID (1UL << 30UL)
  44. static void __iommu_flushall(struct sbus_iommu *iommu)
  45. {
  46. unsigned long tag = iommu->iommu_regs + IOMMU_TAGDIAG;
  47. int entry;
  48. for (entry = 0; entry < 16; entry++) {
  49. upa_writeq(0, tag);
  50. tag += 8UL;
  51. }
  52. upa_readq(iommu->sbus_control_reg);
  53. }
  54. /* Offsets from strbuf_regs */
  55. #define SYSIO_STRBUFREG_BASE 0x2800UL
  56. #define STRBUF_CONTROL (0x2800UL - 0x2800UL) /* Control */
  57. #define STRBUF_PFLUSH (0x2808UL - 0x2800UL) /* Page flush/invalidate */
  58. #define STRBUF_FSYNC (0x2810UL - 0x2800UL) /* Flush synchronization */
  59. #define STRBUF_DRAMDIAG (0x5000UL - 0x2800UL) /* data RAM diagnostic */
  60. #define STRBUF_ERRDIAG (0x5400UL - 0x2800UL) /* error status diagnostics */
  61. #define STRBUF_PTAGDIAG (0x5800UL - 0x2800UL) /* Page tag diagnostics */
  62. #define STRBUF_LTAGDIAG (0x5900UL - 0x2800UL) /* Line tag diagnostics */
  63. #define STRBUF_TAG_VALID 0x02UL
  64. static void sbus_strbuf_flush(struct sbus_iommu *iommu, u32 base, unsigned long npages, int direction)
  65. {
  66. unsigned long n;
  67. int limit;
  68. n = npages;
  69. while (n--)
  70. upa_writeq(base + (n << IO_PAGE_SHIFT),
  71. iommu->strbuf_regs + STRBUF_PFLUSH);
  72. /* If the device could not have possibly put dirty data into
  73. * the streaming cache, no flush-flag synchronization needs
  74. * to be performed.
  75. */
  76. if (direction == SBUS_DMA_TODEVICE)
  77. return;
  78. iommu->strbuf_flushflag = 0UL;
  79. /* Whoopee cushion! */
  80. upa_writeq(__pa(&iommu->strbuf_flushflag),
  81. iommu->strbuf_regs + STRBUF_FSYNC);
  82. upa_readq(iommu->sbus_control_reg);
  83. limit = 100000;
  84. while (iommu->strbuf_flushflag == 0UL) {
  85. limit--;
  86. if (!limit)
  87. break;
  88. udelay(1);
  89. rmb();
  90. }
  91. if (!limit)
  92. printk(KERN_WARNING "sbus_strbuf_flush: flushflag timeout "
  93. "vaddr[%08x] npages[%ld]\n",
  94. base, npages);
  95. }
  96. /* Based largely upon the ppc64 iommu allocator. */
  97. static long sbus_arena_alloc(struct sbus_iommu *iommu, unsigned long npages)
  98. {
  99. struct iommu_arena *arena = &iommu->arena;
  100. unsigned long n, i, start, end, limit;
  101. int pass;
  102. limit = arena->limit;
  103. start = arena->hint;
  104. pass = 0;
  105. again:
  106. n = find_next_zero_bit(arena->map, limit, start);
  107. end = n + npages;
  108. if (unlikely(end >= limit)) {
  109. if (likely(pass < 1)) {
  110. limit = start;
  111. start = 0;
  112. __iommu_flushall(iommu);
  113. pass++;
  114. goto again;
  115. } else {
  116. /* Scanned the whole thing, give up. */
  117. return -1;
  118. }
  119. }
  120. for (i = n; i < end; i++) {
  121. if (test_bit(i, arena->map)) {
  122. start = i + 1;
  123. goto again;
  124. }
  125. }
  126. for (i = n; i < end; i++)
  127. __set_bit(i, arena->map);
  128. arena->hint = end;
  129. return n;
  130. }
  131. static void sbus_arena_free(struct iommu_arena *arena, unsigned long base, unsigned long npages)
  132. {
  133. unsigned long i;
  134. for (i = base; i < (base + npages); i++)
  135. __clear_bit(i, arena->map);
  136. }
  137. static void sbus_iommu_table_init(struct sbus_iommu *iommu, unsigned int tsbsize)
  138. {
  139. unsigned long tsbbase, order, sz, num_tsb_entries;
  140. num_tsb_entries = tsbsize / sizeof(iopte_t);
  141. /* Setup initial software IOMMU state. */
  142. spin_lock_init(&iommu->lock);
  143. /* Allocate and initialize the free area map. */
  144. sz = num_tsb_entries / 8;
  145. sz = (sz + 7UL) & ~7UL;
  146. iommu->arena.map = kzalloc(sz, GFP_KERNEL);
  147. if (!iommu->arena.map) {
  148. prom_printf("PCI_IOMMU: Error, kmalloc(arena.map) failed.\n");
  149. prom_halt();
  150. }
  151. iommu->arena.limit = num_tsb_entries;
  152. /* Now allocate and setup the IOMMU page table itself. */
  153. order = get_order(tsbsize);
  154. tsbbase = __get_free_pages(GFP_KERNEL, order);
  155. if (!tsbbase) {
  156. prom_printf("IOMMU: Error, gfp(tsb) failed.\n");
  157. prom_halt();
  158. }
  159. iommu->page_table = (iopte_t *)tsbbase;
  160. memset(iommu->page_table, 0, tsbsize);
  161. }
  162. static inline iopte_t *alloc_npages(struct sbus_iommu *iommu, unsigned long npages)
  163. {
  164. long entry;
  165. entry = sbus_arena_alloc(iommu, npages);
  166. if (unlikely(entry < 0))
  167. return NULL;
  168. return iommu->page_table + entry;
  169. }
  170. static inline void free_npages(struct sbus_iommu *iommu, dma_addr_t base, unsigned long npages)
  171. {
  172. sbus_arena_free(&iommu->arena, base >> IO_PAGE_SHIFT, npages);
  173. }
  174. void *sbus_alloc_consistent(struct sbus_dev *sdev, size_t size, dma_addr_t *dvma_addr)
  175. {
  176. struct sbus_iommu *iommu;
  177. iopte_t *iopte;
  178. unsigned long flags, order, first_page;
  179. void *ret;
  180. int npages;
  181. size = IO_PAGE_ALIGN(size);
  182. order = get_order(size);
  183. if (order >= 10)
  184. return NULL;
  185. first_page = __get_free_pages(GFP_KERNEL|__GFP_COMP, order);
  186. if (first_page == 0UL)
  187. return NULL;
  188. memset((char *)first_page, 0, PAGE_SIZE << order);
  189. iommu = sdev->bus->iommu;
  190. spin_lock_irqsave(&iommu->lock, flags);
  191. iopte = alloc_npages(iommu, size >> IO_PAGE_SHIFT);
  192. spin_unlock_irqrestore(&iommu->lock, flags);
  193. if (unlikely(iopte == NULL)) {
  194. free_pages(first_page, order);
  195. return NULL;
  196. }
  197. *dvma_addr = (MAP_BASE +
  198. ((iopte - iommu->page_table) << IO_PAGE_SHIFT));
  199. ret = (void *) first_page;
  200. npages = size >> IO_PAGE_SHIFT;
  201. first_page = __pa(first_page);
  202. while (npages--) {
  203. iopte_val(*iopte) = (IOPTE_VALID | IOPTE_CACHE |
  204. IOPTE_WRITE |
  205. (first_page & IOPTE_PAGE));
  206. iopte++;
  207. first_page += IO_PAGE_SIZE;
  208. }
  209. return ret;
  210. }
  211. void sbus_free_consistent(struct sbus_dev *sdev, size_t size, void *cpu, dma_addr_t dvma)
  212. {
  213. struct sbus_iommu *iommu;
  214. iopte_t *iopte;
  215. unsigned long flags, order, npages;
  216. npages = IO_PAGE_ALIGN(size) >> IO_PAGE_SHIFT;
  217. iommu = sdev->bus->iommu;
  218. iopte = iommu->page_table +
  219. ((dvma - MAP_BASE) >> IO_PAGE_SHIFT);
  220. spin_lock_irqsave(&iommu->lock, flags);
  221. free_npages(iommu, dvma - MAP_BASE, npages);
  222. spin_unlock_irqrestore(&iommu->lock, flags);
  223. order = get_order(size);
  224. if (order < 10)
  225. free_pages((unsigned long)cpu, order);
  226. }
  227. dma_addr_t sbus_map_single(struct sbus_dev *sdev, void *ptr, size_t sz, int direction)
  228. {
  229. struct sbus_iommu *iommu;
  230. iopte_t *base;
  231. unsigned long flags, npages, oaddr;
  232. unsigned long i, base_paddr;
  233. u32 bus_addr, ret;
  234. unsigned long iopte_protection;
  235. iommu = sdev->bus->iommu;
  236. if (unlikely(direction == SBUS_DMA_NONE))
  237. BUG();
  238. oaddr = (unsigned long)ptr;
  239. npages = IO_PAGE_ALIGN(oaddr + sz) - (oaddr & IO_PAGE_MASK);
  240. npages >>= IO_PAGE_SHIFT;
  241. spin_lock_irqsave(&iommu->lock, flags);
  242. base = alloc_npages(iommu, npages);
  243. spin_unlock_irqrestore(&iommu->lock, flags);
  244. if (unlikely(!base))
  245. BUG();
  246. bus_addr = (MAP_BASE +
  247. ((base - iommu->page_table) << IO_PAGE_SHIFT));
  248. ret = bus_addr | (oaddr & ~IO_PAGE_MASK);
  249. base_paddr = __pa(oaddr & IO_PAGE_MASK);
  250. iopte_protection = IOPTE_VALID | IOPTE_STBUF | IOPTE_CACHE;
  251. if (direction != SBUS_DMA_TODEVICE)
  252. iopte_protection |= IOPTE_WRITE;
  253. for (i = 0; i < npages; i++, base++, base_paddr += IO_PAGE_SIZE)
  254. iopte_val(*base) = iopte_protection | base_paddr;
  255. return ret;
  256. }
  257. void sbus_unmap_single(struct sbus_dev *sdev, dma_addr_t bus_addr, size_t sz, int direction)
  258. {
  259. struct sbus_iommu *iommu = sdev->bus->iommu;
  260. iopte_t *base;
  261. unsigned long flags, npages, i;
  262. if (unlikely(direction == SBUS_DMA_NONE))
  263. BUG();
  264. npages = IO_PAGE_ALIGN(bus_addr + sz) - (bus_addr & IO_PAGE_MASK);
  265. npages >>= IO_PAGE_SHIFT;
  266. base = iommu->page_table +
  267. ((bus_addr - MAP_BASE) >> IO_PAGE_SHIFT);
  268. bus_addr &= IO_PAGE_MASK;
  269. spin_lock_irqsave(&iommu->lock, flags);
  270. sbus_strbuf_flush(iommu, bus_addr, npages, direction);
  271. for (i = 0; i < npages; i++)
  272. iopte_val(base[i]) = 0UL;
  273. free_npages(iommu, bus_addr - MAP_BASE, npages);
  274. spin_unlock_irqrestore(&iommu->lock, flags);
  275. }
  276. #define SG_ENT_PHYS_ADDRESS(SG) \
  277. (__pa(page_address((SG)->page)) + (SG)->offset)
  278. static inline void fill_sg(iopte_t *iopte, struct scatterlist *sg,
  279. int nused, int nelems, unsigned long iopte_protection)
  280. {
  281. struct scatterlist *dma_sg = sg;
  282. struct scatterlist *sg_end = sg + nelems;
  283. int i;
  284. for (i = 0; i < nused; i++) {
  285. unsigned long pteval = ~0UL;
  286. u32 dma_npages;
  287. dma_npages = ((dma_sg->dma_address & (IO_PAGE_SIZE - 1UL)) +
  288. dma_sg->dma_length +
  289. ((IO_PAGE_SIZE - 1UL))) >> IO_PAGE_SHIFT;
  290. do {
  291. unsigned long offset;
  292. signed int len;
  293. /* If we are here, we know we have at least one
  294. * more page to map. So walk forward until we
  295. * hit a page crossing, and begin creating new
  296. * mappings from that spot.
  297. */
  298. for (;;) {
  299. unsigned long tmp;
  300. tmp = SG_ENT_PHYS_ADDRESS(sg);
  301. len = sg->length;
  302. if (((tmp ^ pteval) >> IO_PAGE_SHIFT) != 0UL) {
  303. pteval = tmp & IO_PAGE_MASK;
  304. offset = tmp & (IO_PAGE_SIZE - 1UL);
  305. break;
  306. }
  307. if (((tmp ^ (tmp + len - 1UL)) >> IO_PAGE_SHIFT) != 0UL) {
  308. pteval = (tmp + IO_PAGE_SIZE) & IO_PAGE_MASK;
  309. offset = 0UL;
  310. len -= (IO_PAGE_SIZE - (tmp & (IO_PAGE_SIZE - 1UL)));
  311. break;
  312. }
  313. sg++;
  314. }
  315. pteval = iopte_protection | (pteval & IOPTE_PAGE);
  316. while (len > 0) {
  317. *iopte++ = __iopte(pteval);
  318. pteval += IO_PAGE_SIZE;
  319. len -= (IO_PAGE_SIZE - offset);
  320. offset = 0;
  321. dma_npages--;
  322. }
  323. pteval = (pteval & IOPTE_PAGE) + len;
  324. sg++;
  325. /* Skip over any tail mappings we've fully mapped,
  326. * adjusting pteval along the way. Stop when we
  327. * detect a page crossing event.
  328. */
  329. while (sg < sg_end &&
  330. (pteval << (64 - IO_PAGE_SHIFT)) != 0UL &&
  331. (pteval == SG_ENT_PHYS_ADDRESS(sg)) &&
  332. ((pteval ^
  333. (SG_ENT_PHYS_ADDRESS(sg) + sg->length - 1UL)) >> IO_PAGE_SHIFT) == 0UL) {
  334. pteval += sg->length;
  335. sg++;
  336. }
  337. if ((pteval << (64 - IO_PAGE_SHIFT)) == 0UL)
  338. pteval = ~0UL;
  339. } while (dma_npages != 0);
  340. dma_sg++;
  341. }
  342. }
  343. int sbus_map_sg(struct sbus_dev *sdev, struct scatterlist *sglist, int nelems, int direction)
  344. {
  345. struct sbus_iommu *iommu;
  346. unsigned long flags, npages, iopte_protection;
  347. iopte_t *base;
  348. u32 dma_base;
  349. struct scatterlist *sgtmp;
  350. int used;
  351. /* Fast path single entry scatterlists. */
  352. if (nelems == 1) {
  353. sglist->dma_address =
  354. sbus_map_single(sdev,
  355. (page_address(sglist->page) + sglist->offset),
  356. sglist->length, direction);
  357. sglist->dma_length = sglist->length;
  358. return 1;
  359. }
  360. iommu = sdev->bus->iommu;
  361. if (unlikely(direction == SBUS_DMA_NONE))
  362. BUG();
  363. npages = prepare_sg(sglist, nelems);
  364. spin_lock_irqsave(&iommu->lock, flags);
  365. base = alloc_npages(iommu, npages);
  366. spin_unlock_irqrestore(&iommu->lock, flags);
  367. if (unlikely(base == NULL))
  368. BUG();
  369. dma_base = MAP_BASE +
  370. ((base - iommu->page_table) << IO_PAGE_SHIFT);
  371. /* Normalize DVMA addresses. */
  372. used = nelems;
  373. sgtmp = sglist;
  374. while (used && sgtmp->dma_length) {
  375. sgtmp->dma_address += dma_base;
  376. sgtmp++;
  377. used--;
  378. }
  379. used = nelems - used;
  380. iopte_protection = IOPTE_VALID | IOPTE_STBUF | IOPTE_CACHE;
  381. if (direction != SBUS_DMA_TODEVICE)
  382. iopte_protection |= IOPTE_WRITE;
  383. fill_sg(base, sglist, used, nelems, iopte_protection);
  384. #ifdef VERIFY_SG
  385. verify_sglist(sglist, nelems, base, npages);
  386. #endif
  387. return used;
  388. }
  389. void sbus_unmap_sg(struct sbus_dev *sdev, struct scatterlist *sglist, int nelems, int direction)
  390. {
  391. struct sbus_iommu *iommu;
  392. iopte_t *base;
  393. unsigned long flags, i, npages;
  394. u32 bus_addr;
  395. if (unlikely(direction == SBUS_DMA_NONE))
  396. BUG();
  397. iommu = sdev->bus->iommu;
  398. bus_addr = sglist->dma_address & IO_PAGE_MASK;
  399. for (i = 1; i < nelems; i++)
  400. if (sglist[i].dma_length == 0)
  401. break;
  402. i--;
  403. npages = (IO_PAGE_ALIGN(sglist[i].dma_address + sglist[i].dma_length) -
  404. bus_addr) >> IO_PAGE_SHIFT;
  405. base = iommu->page_table +
  406. ((bus_addr - MAP_BASE) >> IO_PAGE_SHIFT);
  407. spin_lock_irqsave(&iommu->lock, flags);
  408. sbus_strbuf_flush(iommu, bus_addr, npages, direction);
  409. for (i = 0; i < npages; i++)
  410. iopte_val(base[i]) = 0UL;
  411. free_npages(iommu, bus_addr - MAP_BASE, npages);
  412. spin_unlock_irqrestore(&iommu->lock, flags);
  413. }
  414. void sbus_dma_sync_single_for_cpu(struct sbus_dev *sdev, dma_addr_t bus_addr, size_t sz, int direction)
  415. {
  416. struct sbus_iommu *iommu;
  417. unsigned long flags, npages;
  418. iommu = sdev->bus->iommu;
  419. npages = IO_PAGE_ALIGN(bus_addr + sz) - (bus_addr & IO_PAGE_MASK);
  420. npages >>= IO_PAGE_SHIFT;
  421. bus_addr &= IO_PAGE_MASK;
  422. spin_lock_irqsave(&iommu->lock, flags);
  423. sbus_strbuf_flush(iommu, bus_addr, npages, direction);
  424. spin_unlock_irqrestore(&iommu->lock, flags);
  425. }
  426. void sbus_dma_sync_single_for_device(struct sbus_dev *sdev, dma_addr_t base, size_t size, int direction)
  427. {
  428. }
  429. void sbus_dma_sync_sg_for_cpu(struct sbus_dev *sdev, struct scatterlist *sglist, int nelems, int direction)
  430. {
  431. struct sbus_iommu *iommu;
  432. unsigned long flags, npages, i;
  433. u32 bus_addr;
  434. iommu = sdev->bus->iommu;
  435. bus_addr = sglist[0].dma_address & IO_PAGE_MASK;
  436. for (i = 0; i < nelems; i++) {
  437. if (!sglist[i].dma_length)
  438. break;
  439. }
  440. i--;
  441. npages = (IO_PAGE_ALIGN(sglist[i].dma_address + sglist[i].dma_length)
  442. - bus_addr) >> IO_PAGE_SHIFT;
  443. spin_lock_irqsave(&iommu->lock, flags);
  444. sbus_strbuf_flush(iommu, bus_addr, npages, direction);
  445. spin_unlock_irqrestore(&iommu->lock, flags);
  446. }
  447. void sbus_dma_sync_sg_for_device(struct sbus_dev *sdev, struct scatterlist *sg, int nents, int direction)
  448. {
  449. }
  450. /* Enable 64-bit DVMA mode for the given device. */
  451. void sbus_set_sbus64(struct sbus_dev *sdev, int bursts)
  452. {
  453. struct sbus_iommu *iommu = sdev->bus->iommu;
  454. int slot = sdev->slot;
  455. unsigned long cfg_reg;
  456. u64 val;
  457. cfg_reg = iommu->sbus_control_reg;
  458. switch (slot) {
  459. case 0:
  460. cfg_reg += 0x20UL;
  461. break;
  462. case 1:
  463. cfg_reg += 0x28UL;
  464. break;
  465. case 2:
  466. cfg_reg += 0x30UL;
  467. break;
  468. case 3:
  469. cfg_reg += 0x38UL;
  470. break;
  471. case 13:
  472. cfg_reg += 0x40UL;
  473. break;
  474. case 14:
  475. cfg_reg += 0x48UL;
  476. break;
  477. case 15:
  478. cfg_reg += 0x50UL;
  479. break;
  480. default:
  481. return;
  482. };
  483. val = upa_readq(cfg_reg);
  484. if (val & (1UL << 14UL)) {
  485. /* Extended transfer mode already enabled. */
  486. return;
  487. }
  488. val |= (1UL << 14UL);
  489. if (bursts & DMA_BURST8)
  490. val |= (1UL << 1UL);
  491. if (bursts & DMA_BURST16)
  492. val |= (1UL << 2UL);
  493. if (bursts & DMA_BURST32)
  494. val |= (1UL << 3UL);
  495. if (bursts & DMA_BURST64)
  496. val |= (1UL << 4UL);
  497. upa_writeq(val, cfg_reg);
  498. }
  499. /* INO number to IMAP register offset for SYSIO external IRQ's.
  500. * This should conform to both Sunfire/Wildfire server and Fusion
  501. * desktop designs.
  502. */
  503. #define SYSIO_IMAP_SLOT0 0x2c04UL
  504. #define SYSIO_IMAP_SLOT1 0x2c0cUL
  505. #define SYSIO_IMAP_SLOT2 0x2c14UL
  506. #define SYSIO_IMAP_SLOT3 0x2c1cUL
  507. #define SYSIO_IMAP_SCSI 0x3004UL
  508. #define SYSIO_IMAP_ETH 0x300cUL
  509. #define SYSIO_IMAP_BPP 0x3014UL
  510. #define SYSIO_IMAP_AUDIO 0x301cUL
  511. #define SYSIO_IMAP_PFAIL 0x3024UL
  512. #define SYSIO_IMAP_KMS 0x302cUL
  513. #define SYSIO_IMAP_FLPY 0x3034UL
  514. #define SYSIO_IMAP_SHW 0x303cUL
  515. #define SYSIO_IMAP_KBD 0x3044UL
  516. #define SYSIO_IMAP_MS 0x304cUL
  517. #define SYSIO_IMAP_SER 0x3054UL
  518. #define SYSIO_IMAP_TIM0 0x3064UL
  519. #define SYSIO_IMAP_TIM1 0x306cUL
  520. #define SYSIO_IMAP_UE 0x3074UL
  521. #define SYSIO_IMAP_CE 0x307cUL
  522. #define SYSIO_IMAP_SBERR 0x3084UL
  523. #define SYSIO_IMAP_PMGMT 0x308cUL
  524. #define SYSIO_IMAP_GFX 0x3094UL
  525. #define SYSIO_IMAP_EUPA 0x309cUL
  526. #define bogon ((unsigned long) -1)
  527. static unsigned long sysio_irq_offsets[] = {
  528. /* SBUS Slot 0 --> 3, level 1 --> 7 */
  529. SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0,
  530. SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0,
  531. SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1,
  532. SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1,
  533. SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2,
  534. SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2,
  535. SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3,
  536. SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3,
  537. /* Onboard devices (not relevant/used on SunFire). */
  538. SYSIO_IMAP_SCSI,
  539. SYSIO_IMAP_ETH,
  540. SYSIO_IMAP_BPP,
  541. bogon,
  542. SYSIO_IMAP_AUDIO,
  543. SYSIO_IMAP_PFAIL,
  544. bogon,
  545. bogon,
  546. SYSIO_IMAP_KMS,
  547. SYSIO_IMAP_FLPY,
  548. SYSIO_IMAP_SHW,
  549. SYSIO_IMAP_KBD,
  550. SYSIO_IMAP_MS,
  551. SYSIO_IMAP_SER,
  552. bogon,
  553. bogon,
  554. SYSIO_IMAP_TIM0,
  555. SYSIO_IMAP_TIM1,
  556. bogon,
  557. bogon,
  558. SYSIO_IMAP_UE,
  559. SYSIO_IMAP_CE,
  560. SYSIO_IMAP_SBERR,
  561. SYSIO_IMAP_PMGMT,
  562. };
  563. #undef bogon
  564. #define NUM_SYSIO_OFFSETS ARRAY_SIZE(sysio_irq_offsets)
  565. /* Convert Interrupt Mapping register pointer to associated
  566. * Interrupt Clear register pointer, SYSIO specific version.
  567. */
  568. #define SYSIO_ICLR_UNUSED0 0x3400UL
  569. #define SYSIO_ICLR_SLOT0 0x340cUL
  570. #define SYSIO_ICLR_SLOT1 0x344cUL
  571. #define SYSIO_ICLR_SLOT2 0x348cUL
  572. #define SYSIO_ICLR_SLOT3 0x34ccUL
  573. static unsigned long sysio_imap_to_iclr(unsigned long imap)
  574. {
  575. unsigned long diff = SYSIO_ICLR_UNUSED0 - SYSIO_IMAP_SLOT0;
  576. return imap + diff;
  577. }
  578. unsigned int sbus_build_irq(void *buscookie, unsigned int ino)
  579. {
  580. struct sbus_bus *sbus = (struct sbus_bus *)buscookie;
  581. struct sbus_iommu *iommu = sbus->iommu;
  582. unsigned long reg_base = iommu->sbus_control_reg - 0x2000UL;
  583. unsigned long imap, iclr;
  584. int sbus_level = 0;
  585. imap = sysio_irq_offsets[ino];
  586. if (imap == ((unsigned long)-1)) {
  587. prom_printf("get_irq_translations: Bad SYSIO INO[%x]\n",
  588. ino);
  589. prom_halt();
  590. }
  591. imap += reg_base;
  592. /* SYSIO inconsistency. For external SLOTS, we have to select
  593. * the right ICLR register based upon the lower SBUS irq level
  594. * bits.
  595. */
  596. if (ino >= 0x20) {
  597. iclr = sysio_imap_to_iclr(imap);
  598. } else {
  599. int sbus_slot = (ino & 0x18)>>3;
  600. sbus_level = ino & 0x7;
  601. switch(sbus_slot) {
  602. case 0:
  603. iclr = reg_base + SYSIO_ICLR_SLOT0;
  604. break;
  605. case 1:
  606. iclr = reg_base + SYSIO_ICLR_SLOT1;
  607. break;
  608. case 2:
  609. iclr = reg_base + SYSIO_ICLR_SLOT2;
  610. break;
  611. default:
  612. case 3:
  613. iclr = reg_base + SYSIO_ICLR_SLOT3;
  614. break;
  615. };
  616. iclr += ((unsigned long)sbus_level - 1UL) * 8UL;
  617. }
  618. return build_irq(sbus_level, iclr, imap);
  619. }
  620. /* Error interrupt handling. */
  621. #define SYSIO_UE_AFSR 0x0030UL
  622. #define SYSIO_UE_AFAR 0x0038UL
  623. #define SYSIO_UEAFSR_PPIO 0x8000000000000000UL /* Primary PIO cause */
  624. #define SYSIO_UEAFSR_PDRD 0x4000000000000000UL /* Primary DVMA read cause */
  625. #define SYSIO_UEAFSR_PDWR 0x2000000000000000UL /* Primary DVMA write cause */
  626. #define SYSIO_UEAFSR_SPIO 0x1000000000000000UL /* Secondary PIO is cause */
  627. #define SYSIO_UEAFSR_SDRD 0x0800000000000000UL /* Secondary DVMA read cause */
  628. #define SYSIO_UEAFSR_SDWR 0x0400000000000000UL /* Secondary DVMA write cause*/
  629. #define SYSIO_UEAFSR_RESV1 0x03ff000000000000UL /* Reserved */
  630. #define SYSIO_UEAFSR_DOFF 0x0000e00000000000UL /* Doubleword Offset */
  631. #define SYSIO_UEAFSR_SIZE 0x00001c0000000000UL /* Bad transfer size 2^SIZE */
  632. #define SYSIO_UEAFSR_MID 0x000003e000000000UL /* UPA MID causing the fault */
  633. #define SYSIO_UEAFSR_RESV2 0x0000001fffffffffUL /* Reserved */
  634. static irqreturn_t sysio_ue_handler(int irq, void *dev_id)
  635. {
  636. struct sbus_bus *sbus = dev_id;
  637. struct sbus_iommu *iommu = sbus->iommu;
  638. unsigned long reg_base = iommu->sbus_control_reg - 0x2000UL;
  639. unsigned long afsr_reg, afar_reg;
  640. unsigned long afsr, afar, error_bits;
  641. int reported;
  642. afsr_reg = reg_base + SYSIO_UE_AFSR;
  643. afar_reg = reg_base + SYSIO_UE_AFAR;
  644. /* Latch error status. */
  645. afsr = upa_readq(afsr_reg);
  646. afar = upa_readq(afar_reg);
  647. /* Clear primary/secondary error status bits. */
  648. error_bits = afsr &
  649. (SYSIO_UEAFSR_PPIO | SYSIO_UEAFSR_PDRD | SYSIO_UEAFSR_PDWR |
  650. SYSIO_UEAFSR_SPIO | SYSIO_UEAFSR_SDRD | SYSIO_UEAFSR_SDWR);
  651. upa_writeq(error_bits, afsr_reg);
  652. /* Log the error. */
  653. printk("SYSIO[%x]: Uncorrectable ECC Error, primary error type[%s]\n",
  654. sbus->portid,
  655. (((error_bits & SYSIO_UEAFSR_PPIO) ?
  656. "PIO" :
  657. ((error_bits & SYSIO_UEAFSR_PDRD) ?
  658. "DVMA Read" :
  659. ((error_bits & SYSIO_UEAFSR_PDWR) ?
  660. "DVMA Write" : "???")))));
  661. printk("SYSIO[%x]: DOFF[%lx] SIZE[%lx] MID[%lx]\n",
  662. sbus->portid,
  663. (afsr & SYSIO_UEAFSR_DOFF) >> 45UL,
  664. (afsr & SYSIO_UEAFSR_SIZE) >> 42UL,
  665. (afsr & SYSIO_UEAFSR_MID) >> 37UL);
  666. printk("SYSIO[%x]: AFAR[%016lx]\n", sbus->portid, afar);
  667. printk("SYSIO[%x]: Secondary UE errors [", sbus->portid);
  668. reported = 0;
  669. if (afsr & SYSIO_UEAFSR_SPIO) {
  670. reported++;
  671. printk("(PIO)");
  672. }
  673. if (afsr & SYSIO_UEAFSR_SDRD) {
  674. reported++;
  675. printk("(DVMA Read)");
  676. }
  677. if (afsr & SYSIO_UEAFSR_SDWR) {
  678. reported++;
  679. printk("(DVMA Write)");
  680. }
  681. if (!reported)
  682. printk("(none)");
  683. printk("]\n");
  684. return IRQ_HANDLED;
  685. }
  686. #define SYSIO_CE_AFSR 0x0040UL
  687. #define SYSIO_CE_AFAR 0x0048UL
  688. #define SYSIO_CEAFSR_PPIO 0x8000000000000000UL /* Primary PIO cause */
  689. #define SYSIO_CEAFSR_PDRD 0x4000000000000000UL /* Primary DVMA read cause */
  690. #define SYSIO_CEAFSR_PDWR 0x2000000000000000UL /* Primary DVMA write cause */
  691. #define SYSIO_CEAFSR_SPIO 0x1000000000000000UL /* Secondary PIO cause */
  692. #define SYSIO_CEAFSR_SDRD 0x0800000000000000UL /* Secondary DVMA read cause */
  693. #define SYSIO_CEAFSR_SDWR 0x0400000000000000UL /* Secondary DVMA write cause*/
  694. #define SYSIO_CEAFSR_RESV1 0x0300000000000000UL /* Reserved */
  695. #define SYSIO_CEAFSR_ESYND 0x00ff000000000000UL /* Syndrome Bits */
  696. #define SYSIO_CEAFSR_DOFF 0x0000e00000000000UL /* Double Offset */
  697. #define SYSIO_CEAFSR_SIZE 0x00001c0000000000UL /* Bad transfer size 2^SIZE */
  698. #define SYSIO_CEAFSR_MID 0x000003e000000000UL /* UPA MID causing the fault */
  699. #define SYSIO_CEAFSR_RESV2 0x0000001fffffffffUL /* Reserved */
  700. static irqreturn_t sysio_ce_handler(int irq, void *dev_id)
  701. {
  702. struct sbus_bus *sbus = dev_id;
  703. struct sbus_iommu *iommu = sbus->iommu;
  704. unsigned long reg_base = iommu->sbus_control_reg - 0x2000UL;
  705. unsigned long afsr_reg, afar_reg;
  706. unsigned long afsr, afar, error_bits;
  707. int reported;
  708. afsr_reg = reg_base + SYSIO_CE_AFSR;
  709. afar_reg = reg_base + SYSIO_CE_AFAR;
  710. /* Latch error status. */
  711. afsr = upa_readq(afsr_reg);
  712. afar = upa_readq(afar_reg);
  713. /* Clear primary/secondary error status bits. */
  714. error_bits = afsr &
  715. (SYSIO_CEAFSR_PPIO | SYSIO_CEAFSR_PDRD | SYSIO_CEAFSR_PDWR |
  716. SYSIO_CEAFSR_SPIO | SYSIO_CEAFSR_SDRD | SYSIO_CEAFSR_SDWR);
  717. upa_writeq(error_bits, afsr_reg);
  718. printk("SYSIO[%x]: Correctable ECC Error, primary error type[%s]\n",
  719. sbus->portid,
  720. (((error_bits & SYSIO_CEAFSR_PPIO) ?
  721. "PIO" :
  722. ((error_bits & SYSIO_CEAFSR_PDRD) ?
  723. "DVMA Read" :
  724. ((error_bits & SYSIO_CEAFSR_PDWR) ?
  725. "DVMA Write" : "???")))));
  726. /* XXX Use syndrome and afar to print out module string just like
  727. * XXX UDB CE trap handler does... -DaveM
  728. */
  729. printk("SYSIO[%x]: DOFF[%lx] ECC Syndrome[%lx] Size[%lx] MID[%lx]\n",
  730. sbus->portid,
  731. (afsr & SYSIO_CEAFSR_DOFF) >> 45UL,
  732. (afsr & SYSIO_CEAFSR_ESYND) >> 48UL,
  733. (afsr & SYSIO_CEAFSR_SIZE) >> 42UL,
  734. (afsr & SYSIO_CEAFSR_MID) >> 37UL);
  735. printk("SYSIO[%x]: AFAR[%016lx]\n", sbus->portid, afar);
  736. printk("SYSIO[%x]: Secondary CE errors [", sbus->portid);
  737. reported = 0;
  738. if (afsr & SYSIO_CEAFSR_SPIO) {
  739. reported++;
  740. printk("(PIO)");
  741. }
  742. if (afsr & SYSIO_CEAFSR_SDRD) {
  743. reported++;
  744. printk("(DVMA Read)");
  745. }
  746. if (afsr & SYSIO_CEAFSR_SDWR) {
  747. reported++;
  748. printk("(DVMA Write)");
  749. }
  750. if (!reported)
  751. printk("(none)");
  752. printk("]\n");
  753. return IRQ_HANDLED;
  754. }
  755. #define SYSIO_SBUS_AFSR 0x2010UL
  756. #define SYSIO_SBUS_AFAR 0x2018UL
  757. #define SYSIO_SBAFSR_PLE 0x8000000000000000UL /* Primary Late PIO Error */
  758. #define SYSIO_SBAFSR_PTO 0x4000000000000000UL /* Primary SBUS Timeout */
  759. #define SYSIO_SBAFSR_PBERR 0x2000000000000000UL /* Primary SBUS Error ACK */
  760. #define SYSIO_SBAFSR_SLE 0x1000000000000000UL /* Secondary Late PIO Error */
  761. #define SYSIO_SBAFSR_STO 0x0800000000000000UL /* Secondary SBUS Timeout */
  762. #define SYSIO_SBAFSR_SBERR 0x0400000000000000UL /* Secondary SBUS Error ACK */
  763. #define SYSIO_SBAFSR_RESV1 0x03ff000000000000UL /* Reserved */
  764. #define SYSIO_SBAFSR_RD 0x0000800000000000UL /* Primary was late PIO read */
  765. #define SYSIO_SBAFSR_RESV2 0x0000600000000000UL /* Reserved */
  766. #define SYSIO_SBAFSR_SIZE 0x00001c0000000000UL /* Size of transfer */
  767. #define SYSIO_SBAFSR_MID 0x000003e000000000UL /* MID causing the error */
  768. #define SYSIO_SBAFSR_RESV3 0x0000001fffffffffUL /* Reserved */
  769. static irqreturn_t sysio_sbus_error_handler(int irq, void *dev_id)
  770. {
  771. struct sbus_bus *sbus = dev_id;
  772. struct sbus_iommu *iommu = sbus->iommu;
  773. unsigned long afsr_reg, afar_reg, reg_base;
  774. unsigned long afsr, afar, error_bits;
  775. int reported;
  776. reg_base = iommu->sbus_control_reg - 0x2000UL;
  777. afsr_reg = reg_base + SYSIO_SBUS_AFSR;
  778. afar_reg = reg_base + SYSIO_SBUS_AFAR;
  779. afsr = upa_readq(afsr_reg);
  780. afar = upa_readq(afar_reg);
  781. /* Clear primary/secondary error status bits. */
  782. error_bits = afsr &
  783. (SYSIO_SBAFSR_PLE | SYSIO_SBAFSR_PTO | SYSIO_SBAFSR_PBERR |
  784. SYSIO_SBAFSR_SLE | SYSIO_SBAFSR_STO | SYSIO_SBAFSR_SBERR);
  785. upa_writeq(error_bits, afsr_reg);
  786. /* Log the error. */
  787. printk("SYSIO[%x]: SBUS Error, primary error type[%s] read(%d)\n",
  788. sbus->portid,
  789. (((error_bits & SYSIO_SBAFSR_PLE) ?
  790. "Late PIO Error" :
  791. ((error_bits & SYSIO_SBAFSR_PTO) ?
  792. "Time Out" :
  793. ((error_bits & SYSIO_SBAFSR_PBERR) ?
  794. "Error Ack" : "???")))),
  795. (afsr & SYSIO_SBAFSR_RD) ? 1 : 0);
  796. printk("SYSIO[%x]: size[%lx] MID[%lx]\n",
  797. sbus->portid,
  798. (afsr & SYSIO_SBAFSR_SIZE) >> 42UL,
  799. (afsr & SYSIO_SBAFSR_MID) >> 37UL);
  800. printk("SYSIO[%x]: AFAR[%016lx]\n", sbus->portid, afar);
  801. printk("SYSIO[%x]: Secondary SBUS errors [", sbus->portid);
  802. reported = 0;
  803. if (afsr & SYSIO_SBAFSR_SLE) {
  804. reported++;
  805. printk("(Late PIO Error)");
  806. }
  807. if (afsr & SYSIO_SBAFSR_STO) {
  808. reported++;
  809. printk("(Time Out)");
  810. }
  811. if (afsr & SYSIO_SBAFSR_SBERR) {
  812. reported++;
  813. printk("(Error Ack)");
  814. }
  815. if (!reported)
  816. printk("(none)");
  817. printk("]\n");
  818. /* XXX check iommu/strbuf for further error status XXX */
  819. return IRQ_HANDLED;
  820. }
  821. #define ECC_CONTROL 0x0020UL
  822. #define SYSIO_ECNTRL_ECCEN 0x8000000000000000UL /* Enable ECC Checking */
  823. #define SYSIO_ECNTRL_UEEN 0x4000000000000000UL /* Enable UE Interrupts */
  824. #define SYSIO_ECNTRL_CEEN 0x2000000000000000UL /* Enable CE Interrupts */
  825. #define SYSIO_UE_INO 0x34
  826. #define SYSIO_CE_INO 0x35
  827. #define SYSIO_SBUSERR_INO 0x36
  828. static void __init sysio_register_error_handlers(struct sbus_bus *sbus)
  829. {
  830. struct sbus_iommu *iommu = sbus->iommu;
  831. unsigned long reg_base = iommu->sbus_control_reg - 0x2000UL;
  832. unsigned int irq;
  833. u64 control;
  834. irq = sbus_build_irq(sbus, SYSIO_UE_INO);
  835. if (request_irq(irq, sysio_ue_handler,
  836. IRQF_SHARED, "SYSIO UE", sbus) < 0) {
  837. prom_printf("SYSIO[%x]: Cannot register UE interrupt.\n",
  838. sbus->portid);
  839. prom_halt();
  840. }
  841. irq = sbus_build_irq(sbus, SYSIO_CE_INO);
  842. if (request_irq(irq, sysio_ce_handler,
  843. IRQF_SHARED, "SYSIO CE", sbus) < 0) {
  844. prom_printf("SYSIO[%x]: Cannot register CE interrupt.\n",
  845. sbus->portid);
  846. prom_halt();
  847. }
  848. irq = sbus_build_irq(sbus, SYSIO_SBUSERR_INO);
  849. if (request_irq(irq, sysio_sbus_error_handler,
  850. IRQF_SHARED, "SYSIO SBUS Error", sbus) < 0) {
  851. prom_printf("SYSIO[%x]: Cannot register SBUS Error interrupt.\n",
  852. sbus->portid);
  853. prom_halt();
  854. }
  855. /* Now turn the error interrupts on and also enable ECC checking. */
  856. upa_writeq((SYSIO_ECNTRL_ECCEN |
  857. SYSIO_ECNTRL_UEEN |
  858. SYSIO_ECNTRL_CEEN),
  859. reg_base + ECC_CONTROL);
  860. control = upa_readq(iommu->sbus_control_reg);
  861. control |= 0x100UL; /* SBUS Error Interrupt Enable */
  862. upa_writeq(control, iommu->sbus_control_reg);
  863. }
  864. /* Boot time initialization. */
  865. static void __init sbus_iommu_init(int __node, struct sbus_bus *sbus)
  866. {
  867. const struct linux_prom64_registers *pr;
  868. struct device_node *dp;
  869. struct sbus_iommu *iommu;
  870. unsigned long regs;
  871. u64 control;
  872. int i;
  873. dp = of_find_node_by_phandle(__node);
  874. sbus->portid = of_getintprop_default(dp, "upa-portid", -1);
  875. pr = of_get_property(dp, "reg", NULL);
  876. if (!pr) {
  877. prom_printf("sbus_iommu_init: Cannot map SYSIO control registers.\n");
  878. prom_halt();
  879. }
  880. regs = pr->phys_addr;
  881. iommu = kmalloc(sizeof(*iommu) + SMP_CACHE_BYTES, GFP_ATOMIC);
  882. if (iommu == NULL) {
  883. prom_printf("sbus_iommu_init: Fatal error, kmalloc(iommu) failed\n");
  884. prom_halt();
  885. }
  886. /* Align on E$ line boundary. */
  887. iommu = (struct sbus_iommu *)
  888. (((unsigned long)iommu + (SMP_CACHE_BYTES - 1UL)) &
  889. ~(SMP_CACHE_BYTES - 1UL));
  890. memset(iommu, 0, sizeof(*iommu));
  891. /* Setup spinlock. */
  892. spin_lock_init(&iommu->lock);
  893. /* Init register offsets. */
  894. iommu->iommu_regs = regs + SYSIO_IOMMUREG_BASE;
  895. iommu->strbuf_regs = regs + SYSIO_STRBUFREG_BASE;
  896. /* The SYSIO SBUS control register is used for dummy reads
  897. * in order to ensure write completion.
  898. */
  899. iommu->sbus_control_reg = regs + 0x2000UL;
  900. /* Link into SYSIO software state. */
  901. sbus->iommu = iommu;
  902. printk("SYSIO: UPA portID %x, at %016lx\n",
  903. sbus->portid, regs);
  904. /* Setup for TSB_SIZE=7, TBW_SIZE=0, MMU_DE=1, MMU_EN=1 */
  905. sbus_iommu_table_init(iommu, IO_TSB_SIZE);
  906. control = upa_readq(iommu->iommu_regs + IOMMU_CONTROL);
  907. control = ((7UL << 16UL) |
  908. (0UL << 2UL) |
  909. (1UL << 1UL) |
  910. (1UL << 0UL));
  911. upa_writeq(control, iommu->iommu_regs + IOMMU_CONTROL);
  912. /* Clean out any cruft in the IOMMU using
  913. * diagnostic accesses.
  914. */
  915. for (i = 0; i < 16; i++) {
  916. unsigned long dram = iommu->iommu_regs + IOMMU_DRAMDIAG;
  917. unsigned long tag = iommu->iommu_regs + IOMMU_TAGDIAG;
  918. dram += (unsigned long)i * 8UL;
  919. tag += (unsigned long)i * 8UL;
  920. upa_writeq(0, dram);
  921. upa_writeq(0, tag);
  922. }
  923. upa_readq(iommu->sbus_control_reg);
  924. /* Give the TSB to SYSIO. */
  925. upa_writeq(__pa(iommu->page_table), iommu->iommu_regs + IOMMU_TSBBASE);
  926. /* Setup streaming buffer, DE=1 SB_EN=1 */
  927. control = (1UL << 1UL) | (1UL << 0UL);
  928. upa_writeq(control, iommu->strbuf_regs + STRBUF_CONTROL);
  929. /* Clear out the tags using diagnostics. */
  930. for (i = 0; i < 16; i++) {
  931. unsigned long ptag, ltag;
  932. ptag = iommu->strbuf_regs + STRBUF_PTAGDIAG;
  933. ltag = iommu->strbuf_regs + STRBUF_LTAGDIAG;
  934. ptag += (unsigned long)i * 8UL;
  935. ltag += (unsigned long)i * 8UL;
  936. upa_writeq(0UL, ptag);
  937. upa_writeq(0UL, ltag);
  938. }
  939. /* Enable DVMA arbitration for all devices/slots. */
  940. control = upa_readq(iommu->sbus_control_reg);
  941. control |= 0x3fUL;
  942. upa_writeq(control, iommu->sbus_control_reg);
  943. /* Now some Xfire specific grot... */
  944. if (this_is_starfire)
  945. starfire_hookup(sbus->portid);
  946. sysio_register_error_handlers(sbus);
  947. }
  948. void sbus_fill_device_irq(struct sbus_dev *sdev)
  949. {
  950. struct device_node *dp = of_find_node_by_phandle(sdev->prom_node);
  951. const struct linux_prom_irqs *irqs;
  952. irqs = of_get_property(dp, "interrupts", NULL);
  953. if (!irqs) {
  954. sdev->irqs[0] = 0;
  955. sdev->num_irqs = 0;
  956. } else {
  957. unsigned int pri = irqs[0].pri;
  958. sdev->num_irqs = 1;
  959. if (pri < 0x20)
  960. pri += sdev->slot * 8;
  961. sdev->irqs[0] = sbus_build_irq(sdev->bus, pri);
  962. }
  963. }
  964. void __init sbus_arch_bus_ranges_init(struct device_node *pn, struct sbus_bus *sbus)
  965. {
  966. }
  967. void __init sbus_setup_iommu(struct sbus_bus *sbus, struct device_node *dp)
  968. {
  969. sbus_iommu_init(dp->node, sbus);
  970. }
  971. void __init sbus_setup_arch_props(struct sbus_bus *sbus, struct device_node *dp)
  972. {
  973. }
  974. int __init sbus_arch_preinit(void)
  975. {
  976. return 0;
  977. }
  978. void __init sbus_arch_postinit(void)
  979. {
  980. extern void firetruck_init(void);
  981. firetruck_init();
  982. }