]> err.no Git - linux-2.6/blobdiff - arch/sparc64/kernel/sbus.c
Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6
[linux-2.6] / arch / sparc64 / kernel / sbus.c
index 14f78fb5e890e8dfff2cbe49469ce5313e26cbd9..d1fb13ba02b59e75d56a9259e9f188e0784f3d38 100644 (file)
 
 #define MAP_BASE       ((u32)0xc0000000)
 
-struct sbus_iommu_arena {
-       unsigned long   *map;
-       unsigned int    hint;
-       unsigned int    limit;
-};
-
-struct sbus_iommu {
-       spinlock_t              lock;
-
-       struct sbus_iommu_arena arena;
-
-       iopte_t                 *page_table;
-       unsigned long           strbuf_regs;
-       unsigned long           iommu_regs;
-       unsigned long           sbus_control_reg;
-
-       volatile unsigned long  strbuf_flushflag;
-};
-
 /* Offsets from iommu_regs */
 #define SYSIO_IOMMUREG_BASE    0x2400UL
 #define IOMMU_CONTROL  (0x2400UL - 0x2400UL)   /* IOMMU control register */
@@ -58,18 +39,6 @@ struct sbus_iommu {
 
 #define IOMMU_DRAM_VALID       (1UL << 30UL)
 
-static void __iommu_flushall(struct sbus_iommu *iommu)
-{
-       unsigned long tag = iommu->iommu_regs + IOMMU_TAGDIAG;
-       int entry;
-
-       for (entry = 0; entry < 16; entry++) {
-               upa_writeq(0, tag);
-               tag += 8UL;
-       }
-       upa_readq(iommu->sbus_control_reg);
-}
-
 /* Offsets from strbuf_regs */
 #define SYSIO_STRBUFREG_BASE   0x2800UL
 #define STRBUF_CONTROL (0x2800UL - 0x2800UL)   /* Control */
@@ -82,494 +51,15 @@ static void __iommu_flushall(struct sbus_iommu *iommu)
 
 #define STRBUF_TAG_VALID       0x02UL
 
-static void sbus_strbuf_flush(struct sbus_iommu *iommu, u32 base, unsigned long npages, int direction)
-{
-       unsigned long n;
-       int limit;
-
-       n = npages;
-       while (n--)
-               upa_writeq(base + (n << IO_PAGE_SHIFT),
-                          iommu->strbuf_regs + STRBUF_PFLUSH);
-
-       /* If the device could not have possibly put dirty data into
-        * the streaming cache, no flush-flag synchronization needs
-        * to be performed.
-        */
-       if (direction == SBUS_DMA_TODEVICE)
-               return;
-
-       iommu->strbuf_flushflag = 0UL;
-
-       /* Whoopee cushion! */
-       upa_writeq(__pa(&iommu->strbuf_flushflag),
-                  iommu->strbuf_regs + STRBUF_FSYNC);
-       upa_readq(iommu->sbus_control_reg);
-
-       limit = 100000;
-       while (iommu->strbuf_flushflag == 0UL) {
-               limit--;
-               if (!limit)
-                       break;
-               udelay(1);
-               rmb();
-       }
-       if (!limit)
-               printk(KERN_WARNING "sbus_strbuf_flush: flushflag timeout "
-                      "vaddr[%08x] npages[%ld]\n",
-                      base, npages);
-}
-
-/* Based largely upon the ppc64 iommu allocator.  */
-static long sbus_arena_alloc(struct sbus_iommu *iommu, unsigned long npages)
-{
-       struct sbus_iommu_arena *arena = &iommu->arena;
-       unsigned long n, i, start, end, limit;
-       int pass;
-
-       limit = arena->limit;
-       start = arena->hint;
-       pass = 0;
-
-again:
-       n = find_next_zero_bit(arena->map, limit, start);
-       end = n + npages;
-       if (unlikely(end >= limit)) {
-               if (likely(pass < 1)) {
-                       limit = start;
-                       start = 0;
-                       __iommu_flushall(iommu);
-                       pass++;
-                       goto again;
-               } else {
-                       /* Scanned the whole thing, give up. */
-                       return -1;
-               }
-       }
-
-       for (i = n; i < end; i++) {
-               if (test_bit(i, arena->map)) {
-                       start = i + 1;
-                       goto again;
-               }
-       }
-
-       for (i = n; i < end; i++)
-               __set_bit(i, arena->map);
-
-       arena->hint = end;
-
-       return n;
-}
-
-static void sbus_arena_free(struct sbus_iommu_arena *arena, unsigned long base, unsigned long npages)
-{
-       unsigned long i;
-
-       for (i = base; i < (base + npages); i++)
-               __clear_bit(i, arena->map);
-}
-
-static void sbus_iommu_table_init(struct sbus_iommu *iommu, unsigned int tsbsize)
-{
-       unsigned long tsbbase, order, sz, num_tsb_entries;
-
-       num_tsb_entries = tsbsize / sizeof(iopte_t);
-
-       /* Setup initial software IOMMU state. */
-       spin_lock_init(&iommu->lock);
-
-       /* Allocate and initialize the free area map.  */
-       sz = num_tsb_entries / 8;
-       sz = (sz + 7UL) & ~7UL;
-       iommu->arena.map = kzalloc(sz, GFP_KERNEL);
-       if (!iommu->arena.map) {
-               prom_printf("PCI_IOMMU: Error, kmalloc(arena.map) failed.\n");
-               prom_halt();
-       }
-       iommu->arena.limit = num_tsb_entries;
-
-       /* Now allocate and setup the IOMMU page table itself.  */
-       order = get_order(tsbsize);
-       tsbbase = __get_free_pages(GFP_KERNEL, order);
-       if (!tsbbase) {
-               prom_printf("IOMMU: Error, gfp(tsb) failed.\n");
-               prom_halt();
-       }
-       iommu->page_table = (iopte_t *)tsbbase;
-       memset(iommu->page_table, 0, tsbsize);
-}
-
-static inline iopte_t *alloc_npages(struct sbus_iommu *iommu, unsigned long npages)
-{
-       long entry;
-
-       entry = sbus_arena_alloc(iommu, npages);
-       if (unlikely(entry < 0))
-               return NULL;
-
-       return iommu->page_table + entry;
-}
-
-static inline void free_npages(struct sbus_iommu *iommu, dma_addr_t base, unsigned long npages)
-{
-       sbus_arena_free(&iommu->arena, base >> IO_PAGE_SHIFT, npages);
-}
-
-void *sbus_alloc_consistent(struct sbus_dev *sdev, size_t size, dma_addr_t *dvma_addr)
-{
-       struct sbus_iommu *iommu;
-       iopte_t *iopte;
-       unsigned long flags, order, first_page;
-       void *ret;
-       int npages;
-
-       size = IO_PAGE_ALIGN(size);
-       order = get_order(size);
-       if (order >= 10)
-               return NULL;
-
-       first_page = __get_free_pages(GFP_KERNEL|__GFP_COMP, order);
-       if (first_page == 0UL)
-               return NULL;
-       memset((char *)first_page, 0, PAGE_SIZE << order);
-
-       iommu = sdev->bus->iommu;
-
-       spin_lock_irqsave(&iommu->lock, flags);
-       iopte = alloc_npages(iommu, size >> IO_PAGE_SHIFT);
-       spin_unlock_irqrestore(&iommu->lock, flags);
-
-       if (unlikely(iopte == NULL)) {
-               free_pages(first_page, order);
-               return NULL;
-       }
-
-       *dvma_addr = (MAP_BASE +
-                     ((iopte - iommu->page_table) << IO_PAGE_SHIFT));
-       ret = (void *) first_page;
-       npages = size >> IO_PAGE_SHIFT;
-       first_page = __pa(first_page);
-       while (npages--) {
-               iopte_val(*iopte) = (IOPTE_VALID | IOPTE_CACHE |
-                                    IOPTE_WRITE |
-                                    (first_page & IOPTE_PAGE));
-               iopte++;
-               first_page += IO_PAGE_SIZE;
-       }
-
-       return ret;
-}
-
-void sbus_free_consistent(struct sbus_dev *sdev, size_t size, void *cpu, dma_addr_t dvma)
-{
-       struct sbus_iommu *iommu;
-       iopte_t *iopte;
-       unsigned long flags, order, npages;
-
-       npages = IO_PAGE_ALIGN(size) >> IO_PAGE_SHIFT;
-       iommu = sdev->bus->iommu;
-       iopte = iommu->page_table +
-               ((dvma - MAP_BASE) >> IO_PAGE_SHIFT);
-
-       spin_lock_irqsave(&iommu->lock, flags);
-
-       free_npages(iommu, dvma - MAP_BASE, npages);
-
-       spin_unlock_irqrestore(&iommu->lock, flags);
-
-       order = get_order(size);
-       if (order < 10)
-               free_pages((unsigned long)cpu, order);
-}
-
-dma_addr_t sbus_map_single(struct sbus_dev *sdev, void *ptr, size_t sz, int direction)
-{
-       struct sbus_iommu *iommu;
-       iopte_t *base;
-       unsigned long flags, npages, oaddr;
-       unsigned long i, base_paddr;
-       u32 bus_addr, ret;
-       unsigned long iopte_protection;
-
-       iommu = sdev->bus->iommu;
-
-       if (unlikely(direction == SBUS_DMA_NONE))
-               BUG();
-
-       oaddr = (unsigned long)ptr;
-       npages = IO_PAGE_ALIGN(oaddr + sz) - (oaddr & IO_PAGE_MASK);
-       npages >>= IO_PAGE_SHIFT;
-
-       spin_lock_irqsave(&iommu->lock, flags);
-       base = alloc_npages(iommu, npages);
-       spin_unlock_irqrestore(&iommu->lock, flags);
-
-       if (unlikely(!base))
-               BUG();
-
-       bus_addr = (MAP_BASE +
-                   ((base - iommu->page_table) << IO_PAGE_SHIFT));
-       ret = bus_addr | (oaddr & ~IO_PAGE_MASK);
-       base_paddr = __pa(oaddr & IO_PAGE_MASK);
-
-       iopte_protection = IOPTE_VALID | IOPTE_STBUF | IOPTE_CACHE;
-       if (direction != SBUS_DMA_TODEVICE)
-               iopte_protection |= IOPTE_WRITE;
-
-       for (i = 0; i < npages; i++, base++, base_paddr += IO_PAGE_SIZE)
-               iopte_val(*base) = iopte_protection | base_paddr;
-
-       return ret;
-}
-
-void sbus_unmap_single(struct sbus_dev *sdev, dma_addr_t bus_addr, size_t sz, int direction)
-{
-       struct sbus_iommu *iommu = sdev->bus->iommu;
-       iopte_t *base;
-       unsigned long flags, npages, i;
-
-       if (unlikely(direction == SBUS_DMA_NONE))
-               BUG();
-
-       npages = IO_PAGE_ALIGN(bus_addr + sz) - (bus_addr & IO_PAGE_MASK);
-       npages >>= IO_PAGE_SHIFT;
-       base = iommu->page_table +
-               ((bus_addr - MAP_BASE) >> IO_PAGE_SHIFT);
-
-       bus_addr &= IO_PAGE_MASK;
-
-       spin_lock_irqsave(&iommu->lock, flags);
-       sbus_strbuf_flush(iommu, bus_addr, npages, direction);
-       for (i = 0; i < npages; i++)
-               iopte_val(base[i]) = 0UL;
-       free_npages(iommu, bus_addr - MAP_BASE, npages);
-       spin_unlock_irqrestore(&iommu->lock, flags);
-}
-
-#define SG_ENT_PHYS_ADDRESS(SG)        \
-       (__pa(page_address((SG)->page)) + (SG)->offset)
-
-static inline void fill_sg(iopte_t *iopte, struct scatterlist *sg,
-                          int nused, int nelems, unsigned long iopte_protection)
-{
-       struct scatterlist *dma_sg = sg;
-       struct scatterlist *sg_end = sg + nelems;
-       int i;
-
-       for (i = 0; i < nused; i++) {
-               unsigned long pteval = ~0UL;
-               u32 dma_npages;
-
-               dma_npages = ((dma_sg->dma_address & (IO_PAGE_SIZE - 1UL)) +
-                             dma_sg->dma_length +
-                             ((IO_PAGE_SIZE - 1UL))) >> IO_PAGE_SHIFT;
-               do {
-                       unsigned long offset;
-                       signed int len;
-
-                       /* If we are here, we know we have at least one
-                        * more page to map.  So walk forward until we
-                        * hit a page crossing, and begin creating new
-                        * mappings from that spot.
-                        */
-                       for (;;) {
-                               unsigned long tmp;
-
-                               tmp = SG_ENT_PHYS_ADDRESS(sg);
-                               len = sg->length;
-                               if (((tmp ^ pteval) >> IO_PAGE_SHIFT) != 0UL) {
-                                       pteval = tmp & IO_PAGE_MASK;
-                                       offset = tmp & (IO_PAGE_SIZE - 1UL);
-                                       break;
-                               }
-                               if (((tmp ^ (tmp + len - 1UL)) >> IO_PAGE_SHIFT) != 0UL) {
-                                       pteval = (tmp + IO_PAGE_SIZE) & IO_PAGE_MASK;
-                                       offset = 0UL;
-                                       len -= (IO_PAGE_SIZE - (tmp & (IO_PAGE_SIZE - 1UL)));
-                                       break;
-                               }
-                               sg++;
-                       }
-
-                       pteval = iopte_protection | (pteval & IOPTE_PAGE);
-                       while (len > 0) {
-                               *iopte++ = __iopte(pteval);
-                               pteval += IO_PAGE_SIZE;
-                               len -= (IO_PAGE_SIZE - offset);
-                               offset = 0;
-                               dma_npages--;
-                       }
-
-                       pteval = (pteval & IOPTE_PAGE) + len;
-                       sg++;
-
-                       /* Skip over any tail mappings we've fully mapped,
-                        * adjusting pteval along the way.  Stop when we
-                        * detect a page crossing event.
-                        */
-                       while (sg < sg_end &&
-                              (pteval << (64 - IO_PAGE_SHIFT)) != 0UL &&
-                              (pteval == SG_ENT_PHYS_ADDRESS(sg)) &&
-                              ((pteval ^
-                                (SG_ENT_PHYS_ADDRESS(sg) + sg->length - 1UL)) >> IO_PAGE_SHIFT) == 0UL) {
-                               pteval += sg->length;
-                               sg++;
-                       }
-                       if ((pteval << (64 - IO_PAGE_SHIFT)) == 0UL)
-                               pteval = ~0UL;
-               } while (dma_npages != 0);
-               dma_sg++;
-       }
-}
-
-int sbus_map_sg(struct sbus_dev *sdev, struct scatterlist *sglist, int nelems, int direction)
-{
-       struct sbus_iommu *iommu;
-       unsigned long flags, npages, iopte_protection;
-       iopte_t *base;
-       u32 dma_base;
-       struct scatterlist *sgtmp;
-       int used;
-
-       /* Fast path single entry scatterlists. */
-       if (nelems == 1) {
-               sglist->dma_address =
-                       sbus_map_single(sdev,
-                                       (page_address(sglist->page) + sglist->offset),
-                                       sglist->length, direction);
-               sglist->dma_length = sglist->length;
-               return 1;
-       }
-
-       iommu = sdev->bus->iommu;
-
-       if (unlikely(direction == SBUS_DMA_NONE))
-               BUG();
-
-       npages = prepare_sg(sglist, nelems);
-
-       spin_lock_irqsave(&iommu->lock, flags);
-       base = alloc_npages(iommu, npages);
-       spin_unlock_irqrestore(&iommu->lock, flags);
-
-       if (unlikely(base == NULL))
-               BUG();
-
-       dma_base = MAP_BASE +
-               ((base - iommu->page_table) << IO_PAGE_SHIFT);
-
-       /* Normalize DVMA addresses. */
-       used = nelems;
-
-       sgtmp = sglist;
-       while (used && sgtmp->dma_length) {
-               sgtmp->dma_address += dma_base;
-               sgtmp++;
-               used--;
-       }
-       used = nelems - used;
-
-       iopte_protection = IOPTE_VALID | IOPTE_STBUF | IOPTE_CACHE;
-       if (direction != SBUS_DMA_TODEVICE)
-               iopte_protection |= IOPTE_WRITE;
-
-       fill_sg(base, sglist, used, nelems, iopte_protection);
-
-#ifdef VERIFY_SG
-       verify_sglist(sglist, nelems, base, npages);
-#endif
-
-       return used;
-}
-
-void sbus_unmap_sg(struct sbus_dev *sdev, struct scatterlist *sglist, int nelems, int direction)
-{
-       struct sbus_iommu *iommu;
-       iopte_t *base;
-       unsigned long flags, i, npages;
-       u32 bus_addr;
-
-       if (unlikely(direction == SBUS_DMA_NONE))
-               BUG();
-
-       iommu = sdev->bus->iommu;
-
-       bus_addr = sglist->dma_address & IO_PAGE_MASK;
-
-       for (i = 1; i < nelems; i++)
-               if (sglist[i].dma_length == 0)
-                       break;
-       i--;
-       npages = (IO_PAGE_ALIGN(sglist[i].dma_address + sglist[i].dma_length) -
-                 bus_addr) >> IO_PAGE_SHIFT;
-
-       base = iommu->page_table +
-               ((bus_addr - MAP_BASE) >> IO_PAGE_SHIFT);
-
-       spin_lock_irqsave(&iommu->lock, flags);
-       sbus_strbuf_flush(iommu, bus_addr, npages, direction);
-       for (i = 0; i < npages; i++)
-               iopte_val(base[i]) = 0UL;
-       free_npages(iommu, bus_addr - MAP_BASE, npages);
-       spin_unlock_irqrestore(&iommu->lock, flags);
-}
-
-void sbus_dma_sync_single_for_cpu(struct sbus_dev *sdev, dma_addr_t bus_addr, size_t sz, int direction)
-{
-       struct sbus_iommu *iommu;
-       unsigned long flags, npages;
-
-       iommu = sdev->bus->iommu;
-
-       npages = IO_PAGE_ALIGN(bus_addr + sz) - (bus_addr & IO_PAGE_MASK);
-       npages >>= IO_PAGE_SHIFT;
-       bus_addr &= IO_PAGE_MASK;
-
-       spin_lock_irqsave(&iommu->lock, flags);
-       sbus_strbuf_flush(iommu, bus_addr, npages, direction);
-       spin_unlock_irqrestore(&iommu->lock, flags);
-}
-
-void sbus_dma_sync_single_for_device(struct sbus_dev *sdev, dma_addr_t base, size_t size, int direction)
-{
-}
-
-void sbus_dma_sync_sg_for_cpu(struct sbus_dev *sdev, struct scatterlist *sglist, int nelems, int direction)
-{
-       struct sbus_iommu *iommu;
-       unsigned long flags, npages, i;
-       u32 bus_addr;
-
-       iommu = sdev->bus->iommu;
-
-       bus_addr = sglist[0].dma_address & IO_PAGE_MASK;
-       for (i = 0; i < nelems; i++) {
-               if (!sglist[i].dma_length)
-                       break;
-       }
-       i--;
-       npages = (IO_PAGE_ALIGN(sglist[i].dma_address + sglist[i].dma_length)
-                 - bus_addr) >> IO_PAGE_SHIFT;
-
-       spin_lock_irqsave(&iommu->lock, flags);
-       sbus_strbuf_flush(iommu, bus_addr, npages, direction);
-       spin_unlock_irqrestore(&iommu->lock, flags);
-}
-
-void sbus_dma_sync_sg_for_device(struct sbus_dev *sdev, struct scatterlist *sg, int nents, int direction)
-{
-}
-
 /* Enable 64-bit DVMA mode for the given device. */
 void sbus_set_sbus64(struct sbus_dev *sdev, int bursts)
 {
-       struct sbus_iommu *iommu = sdev->bus->iommu;
+       struct iommu *iommu = sdev->ofdev.dev.archdata.iommu;
        int slot = sdev->slot;
        unsigned long cfg_reg;
        u64 val;
 
-       cfg_reg = iommu->sbus_control_reg;
+       cfg_reg = iommu->write_complete_reg;
        switch (slot) {
        case 0:
                cfg_reg += 0x20UL;
@@ -620,29 +110,29 @@ void sbus_set_sbus64(struct sbus_dev *sdev, int bursts)
  * This should conform to both Sunfire/Wildfire server and Fusion
  * desktop designs.
  */
-#define SYSIO_IMAP_SLOT0       0x2c04UL
-#define SYSIO_IMAP_SLOT1       0x2c0cUL
-#define SYSIO_IMAP_SLOT2       0x2c14UL
-#define SYSIO_IMAP_SLOT3       0x2c1cUL
-#define SYSIO_IMAP_SCSI                0x3004UL
-#define SYSIO_IMAP_ETH         0x300cUL
-#define SYSIO_IMAP_BPP         0x3014UL
-#define SYSIO_IMAP_AUDIO       0x301cUL
-#define SYSIO_IMAP_PFAIL       0x3024UL
-#define SYSIO_IMAP_KMS         0x302cUL
-#define SYSIO_IMAP_FLPY                0x3034UL
-#define SYSIO_IMAP_SHW         0x303cUL
-#define SYSIO_IMAP_KBD         0x3044UL
-#define SYSIO_IMAP_MS          0x304cUL
-#define SYSIO_IMAP_SER         0x3054UL
-#define SYSIO_IMAP_TIM0                0x3064UL
-#define SYSIO_IMAP_TIM1                0x306cUL
-#define SYSIO_IMAP_UE          0x3074UL
-#define SYSIO_IMAP_CE          0x307cUL
-#define SYSIO_IMAP_SBERR       0x3084UL
-#define SYSIO_IMAP_PMGMT       0x308cUL
-#define SYSIO_IMAP_GFX         0x3094UL
-#define SYSIO_IMAP_EUPA                0x309cUL
+#define SYSIO_IMAP_SLOT0       0x2c00UL
+#define SYSIO_IMAP_SLOT1       0x2c08UL
+#define SYSIO_IMAP_SLOT2       0x2c10UL
+#define SYSIO_IMAP_SLOT3       0x2c18UL
+#define SYSIO_IMAP_SCSI                0x3000UL
+#define SYSIO_IMAP_ETH         0x3008UL
+#define SYSIO_IMAP_BPP         0x3010UL
+#define SYSIO_IMAP_AUDIO       0x3018UL
+#define SYSIO_IMAP_PFAIL       0x3020UL
+#define SYSIO_IMAP_KMS         0x3028UL
+#define SYSIO_IMAP_FLPY                0x3030UL
+#define SYSIO_IMAP_SHW         0x3038UL
+#define SYSIO_IMAP_KBD         0x3040UL
+#define SYSIO_IMAP_MS          0x3048UL
+#define SYSIO_IMAP_SER         0x3050UL
+#define SYSIO_IMAP_TIM0                0x3060UL
+#define SYSIO_IMAP_TIM1                0x3068UL
+#define SYSIO_IMAP_UE          0x3070UL
+#define SYSIO_IMAP_CE          0x3078UL
+#define SYSIO_IMAP_SBERR       0x3080UL
+#define SYSIO_IMAP_PMGMT       0x3088UL
+#define SYSIO_IMAP_GFX         0x3090UL
+#define SYSIO_IMAP_EUPA                0x3098UL
 
 #define bogon     ((unsigned long) -1)
 static unsigned long sysio_irq_offsets[] = {
@@ -691,10 +181,10 @@ static unsigned long sysio_irq_offsets[] = {
  * Interrupt Clear register pointer, SYSIO specific version.
  */
 #define SYSIO_ICLR_UNUSED0     0x3400UL
-#define SYSIO_ICLR_SLOT0       0x340cUL
-#define SYSIO_ICLR_SLOT1       0x344cUL
-#define SYSIO_ICLR_SLOT2       0x348cUL
-#define SYSIO_ICLR_SLOT3       0x34ccUL
+#define SYSIO_ICLR_SLOT0       0x3408UL
+#define SYSIO_ICLR_SLOT1       0x3448UL
+#define SYSIO_ICLR_SLOT2       0x3488UL
+#define SYSIO_ICLR_SLOT3       0x34c8UL
 static unsigned long sysio_imap_to_iclr(unsigned long imap)
 {
        unsigned long diff = SYSIO_ICLR_UNUSED0 - SYSIO_IMAP_SLOT0;
@@ -704,8 +194,8 @@ static unsigned long sysio_imap_to_iclr(unsigned long imap)
 unsigned int sbus_build_irq(void *buscookie, unsigned int ino)
 {
        struct sbus_bus *sbus = (struct sbus_bus *)buscookie;
-       struct sbus_iommu *iommu = sbus->iommu;
-       unsigned long reg_base = iommu->sbus_control_reg - 0x2000UL;
+       struct iommu *iommu = sbus->ofdev.dev.archdata.iommu;
+       unsigned long reg_base = iommu->write_complete_reg - 0x2000UL;
        unsigned long imap, iclr;
        int sbus_level = 0;
 
@@ -766,8 +256,8 @@ unsigned int sbus_build_irq(void *buscookie, unsigned int ino)
 static irqreturn_t sysio_ue_handler(int irq, void *dev_id)
 {
        struct sbus_bus *sbus = dev_id;
-       struct sbus_iommu *iommu = sbus->iommu;
-       unsigned long reg_base = iommu->sbus_control_reg - 0x2000UL;
+       struct iommu *iommu = sbus->ofdev.dev.archdata.iommu;
+       unsigned long reg_base = iommu->write_complete_reg - 0x2000UL;
        unsigned long afsr_reg, afar_reg;
        unsigned long afsr, afar, error_bits;
        int reported;
@@ -838,8 +328,8 @@ static irqreturn_t sysio_ue_handler(int irq, void *dev_id)
 static irqreturn_t sysio_ce_handler(int irq, void *dev_id)
 {
        struct sbus_bus *sbus = dev_id;
-       struct sbus_iommu *iommu = sbus->iommu;
-       unsigned long reg_base = iommu->sbus_control_reg - 0x2000UL;
+       struct iommu *iommu = sbus->ofdev.dev.archdata.iommu;
+       unsigned long reg_base = iommu->write_complete_reg - 0x2000UL;
        unsigned long afsr_reg, afar_reg;
        unsigned long afsr, afar, error_bits;
        int reported;
@@ -915,12 +405,12 @@ static irqreturn_t sysio_ce_handler(int irq, void *dev_id)
 static irqreturn_t sysio_sbus_error_handler(int irq, void *dev_id)
 {
        struct sbus_bus *sbus = dev_id;
-       struct sbus_iommu *iommu = sbus->iommu;
+       struct iommu *iommu = sbus->ofdev.dev.archdata.iommu;
        unsigned long afsr_reg, afar_reg, reg_base;
        unsigned long afsr, afar, error_bits;
        int reported;
 
-       reg_base = iommu->sbus_control_reg - 0x2000UL;
+       reg_base = iommu->write_complete_reg - 0x2000UL;
        afsr_reg = reg_base + SYSIO_SBUS_AFSR;
        afar_reg = reg_base + SYSIO_SBUS_AFAR;
 
@@ -982,30 +472,30 @@ static irqreturn_t sysio_sbus_error_handler(int irq, void *dev_id)
 
 static void __init sysio_register_error_handlers(struct sbus_bus *sbus)
 {
-       struct sbus_iommu *iommu = sbus->iommu;
-       unsigned long reg_base = iommu->sbus_control_reg - 0x2000UL;
+       struct iommu *iommu = sbus->ofdev.dev.archdata.iommu;
+       unsigned long reg_base = iommu->write_complete_reg - 0x2000UL;
        unsigned int irq;
        u64 control;
 
        irq = sbus_build_irq(sbus, SYSIO_UE_INO);
-       if (request_irq(irq, sysio_ue_handler,
-                       IRQF_SHARED, "SYSIO UE", sbus) < 0) {
+       if (request_irq(irq, sysio_ue_handler, 0,
+                       "SYSIO_UE", sbus) < 0) {
                prom_printf("SYSIO[%x]: Cannot register UE interrupt.\n",
                            sbus->portid);
                prom_halt();
        }
 
        irq = sbus_build_irq(sbus, SYSIO_CE_INO);
-       if (request_irq(irq, sysio_ce_handler,
-                       IRQF_SHARED, "SYSIO CE", sbus) < 0) {
+       if (request_irq(irq, sysio_ce_handler, 0,
+                       "SYSIO_CE", sbus) < 0) {
                prom_printf("SYSIO[%x]: Cannot register CE interrupt.\n",
                            sbus->portid);
                prom_halt();
        }
 
        irq = sbus_build_irq(sbus, SYSIO_SBUSERR_INO);
-       if (request_irq(irq, sysio_sbus_error_handler,
-                       IRQF_SHARED, "SYSIO SBUS Error", sbus) < 0) {
+       if (request_irq(irq, sysio_sbus_error_handler, 0,
+                       "SYSIO_SBERR", sbus) < 0) {
                prom_printf("SYSIO[%x]: Cannot register SBUS Error interrupt.\n",
                            sbus->portid);
                prom_halt();
@@ -1017,18 +507,19 @@ static void __init sysio_register_error_handlers(struct sbus_bus *sbus)
                    SYSIO_ECNTRL_CEEN),
                   reg_base + ECC_CONTROL);
 
-       control = upa_readq(iommu->sbus_control_reg);
+       control = upa_readq(iommu->write_complete_reg);
        control |= 0x100UL; /* SBUS Error Interrupt Enable */
-       upa_writeq(control, iommu->sbus_control_reg);
+       upa_writeq(control, iommu->write_complete_reg);
 }
 
 /* Boot time initialization. */
 static void __init sbus_iommu_init(int __node, struct sbus_bus *sbus)
 {
-       struct linux_prom64_registers *pr;
+       const struct linux_prom64_registers *pr;
        struct device_node *dp;
-       struct sbus_iommu *iommu;
-       unsigned long regs;
+       struct iommu *iommu;
+       struct strbuf *strbuf;
+       unsigned long regs, reg_base;
        u64 control;
        int i;
 
@@ -1038,79 +529,93 @@ static void __init sbus_iommu_init(int __node, struct sbus_bus *sbus)
 
        pr = of_get_property(dp, "reg", NULL);
        if (!pr) {
-               prom_printf("sbus_iommu_init: Cannot map SYSIO control registers.\n");
+               prom_printf("sbus_iommu_init: Cannot map SYSIO "
+                           "control registers.\n");
                prom_halt();
        }
        regs = pr->phys_addr;
 
-       iommu = kmalloc(sizeof(*iommu) + SMP_CACHE_BYTES, GFP_ATOMIC);
-       if (iommu == NULL) {
-               prom_printf("sbus_iommu_init: Fatal error, kmalloc(iommu) failed\n");
-               prom_halt();
-       }
-
-       /* Align on E$ line boundary. */
-       iommu = (struct sbus_iommu *)
-               (((unsigned long)iommu + (SMP_CACHE_BYTES - 1UL)) &
-                ~(SMP_CACHE_BYTES - 1UL));
-
-       memset(iommu, 0, sizeof(*iommu));
-
-       /* Setup spinlock. */
-       spin_lock_init(&iommu->lock);
-
-       /* Init register offsets. */
-       iommu->iommu_regs = regs + SYSIO_IOMMUREG_BASE;
-       iommu->strbuf_regs = regs + SYSIO_STRBUFREG_BASE;
+       iommu = kzalloc(sizeof(*iommu), GFP_ATOMIC);
+       if (!iommu)
+               goto fatal_memory_error;
+       strbuf = kzalloc(sizeof(*strbuf), GFP_ATOMIC);
+       if (!strbuf)
+               goto fatal_memory_error;
+
+       sbus->ofdev.dev.archdata.iommu = iommu;
+       sbus->ofdev.dev.archdata.stc = strbuf;
+
+       reg_base = regs + SYSIO_IOMMUREG_BASE;
+       iommu->iommu_control = reg_base + IOMMU_CONTROL;
+       iommu->iommu_tsbbase = reg_base + IOMMU_TSBBASE;
+       iommu->iommu_flush = reg_base + IOMMU_FLUSH;
+       iommu->iommu_tags = iommu->iommu_control +
+               (IOMMU_TAGDIAG - IOMMU_CONTROL);
+
+       reg_base = regs + SYSIO_STRBUFREG_BASE;
+       strbuf->strbuf_control = reg_base + STRBUF_CONTROL;
+       strbuf->strbuf_pflush = reg_base + STRBUF_PFLUSH;
+       strbuf->strbuf_fsync = reg_base + STRBUF_FSYNC;
+
+       strbuf->strbuf_enabled = 1;
+
+       strbuf->strbuf_flushflag = (volatile unsigned long *)
+               ((((unsigned long)&strbuf->__flushflag_buf[0])
+                 + 63UL)
+                & ~63UL);
+       strbuf->strbuf_flushflag_pa = (unsigned long)
+               __pa(strbuf->strbuf_flushflag);
 
        /* The SYSIO SBUS control register is used for dummy reads
         * in order to ensure write completion.
         */
-       iommu->sbus_control_reg = regs + 0x2000UL;
-
-       /* Link into SYSIO software state. */
-       sbus->iommu = iommu;
+       iommu->write_complete_reg = regs + 0x2000UL;
 
        printk("SYSIO: UPA portID %x, at %016lx\n",
               sbus->portid, regs);
 
        /* Setup for TSB_SIZE=7, TBW_SIZE=0, MMU_DE=1, MMU_EN=1 */
-       sbus_iommu_table_init(iommu, IO_TSB_SIZE);
+       if (iommu_table_init(iommu, IO_TSB_SIZE, MAP_BASE, 0xffffffff))
+               goto fatal_memory_error;
 
-       control = upa_readq(iommu->iommu_regs + IOMMU_CONTROL);
+       control = upa_readq(iommu->iommu_control);
        control = ((7UL << 16UL)        |
                   (0UL << 2UL)         |
                   (1UL << 1UL)         |
                   (1UL << 0UL));
-       upa_writeq(control, iommu->iommu_regs + IOMMU_CONTROL);
+       upa_writeq(control, iommu->iommu_control);
 
        /* Clean out any cruft in the IOMMU using
         * diagnostic accesses.
         */
        for (i = 0; i < 16; i++) {
-               unsigned long dram = iommu->iommu_regs + IOMMU_DRAMDIAG;
-               unsigned long tag = iommu->iommu_regs + IOMMU_TAGDIAG;
+               unsigned long dram, tag;
+
+               dram = iommu->iommu_control + (IOMMU_DRAMDIAG - IOMMU_CONTROL);
+               tag = iommu->iommu_control + (IOMMU_TAGDIAG - IOMMU_CONTROL);
 
                dram += (unsigned long)i * 8UL;
                tag += (unsigned long)i * 8UL;
                upa_writeq(0, dram);
                upa_writeq(0, tag);
        }
-       upa_readq(iommu->sbus_control_reg);
+       upa_readq(iommu->write_complete_reg);
 
        /* Give the TSB to SYSIO. */
-       upa_writeq(__pa(iommu->page_table), iommu->iommu_regs + IOMMU_TSBBASE);
+       upa_writeq(__pa(iommu->page_table), iommu->iommu_tsbbase);
 
        /* Setup streaming buffer, DE=1 SB_EN=1 */
        control = (1UL << 1UL) | (1UL << 0UL);
-       upa_writeq(control, iommu->strbuf_regs + STRBUF_CONTROL);
+       upa_writeq(control, strbuf->strbuf_control);
 
        /* Clear out the tags using diagnostics. */
        for (i = 0; i < 16; i++) {
                unsigned long ptag, ltag;
 
-               ptag = iommu->strbuf_regs + STRBUF_PTAGDIAG;
-               ltag = iommu->strbuf_regs + STRBUF_LTAGDIAG;
+               ptag = strbuf->strbuf_control +
+                       (STRBUF_PTAGDIAG - STRBUF_CONTROL);
+               ltag = strbuf->strbuf_control +
+                       (STRBUF_LTAGDIAG - STRBUF_CONTROL);
                ptag += (unsigned long)i * 8UL;
                ltag += (unsigned long)i * 8UL;
 
@@ -1119,21 +624,25 @@ static void __init sbus_iommu_init(int __node, struct sbus_bus *sbus)
        }
 
        /* Enable DVMA arbitration for all devices/slots. */
-       control = upa_readq(iommu->sbus_control_reg);
+       control = upa_readq(iommu->write_complete_reg);
        control |= 0x3fUL;
-       upa_writeq(control, iommu->sbus_control_reg);
+       upa_writeq(control, iommu->write_complete_reg);
 
        /* Now some Xfire specific grot... */
        if (this_is_starfire)
                starfire_hookup(sbus->portid);
 
        sysio_register_error_handlers(sbus);
+       return;
+
+fatal_memory_error:
+       prom_printf("sbus_iommu_init: Fatal memory allocation error.\n");
 }
 
 void sbus_fill_device_irq(struct sbus_dev *sdev)
 {
        struct device_node *dp = of_find_node_by_phandle(sdev->prom_node);
-       struct linux_prom_irqs *irqs;
+       const struct linux_prom_irqs *irqs;
 
        irqs = of_get_property(dp, "interrupts", NULL);
        if (!irqs) {