7 #include <linux/kernel.h>
9 #include <linux/slab.h>
13 #include <linux/bitops.h>
18 #include <asm/pgalloc.h>
19 #include <asm/pgtable.h>
23 #include <asm/cacheflush.h>
24 #include <asm/tlbflush.h>
26 #include <asm/oplib.h>
30 #define IOD(x) printk(x)
32 #define IOD(x) do { } while (0)
35 #define IOPERM (IOUPTE_CACHE | IOUPTE_WRITE | IOUPTE_VALID)
36 #define MKIOPTE(phys) __iopte((((phys)>>4) & IOUPTE_PAGE) | IOPERM)
45 prom_printf(
"SUN4D: Cannot alloc iounit, halting.\n");
58 prom_printf(
"SUN4D: Cannot map External Page Table.");
62 op->
dev.archdata.iommu = iounit;
71 static int __init iounit_init(
void)
76 for_each_node_by_name(dp,
"sbi") {
79 iounit_iommu_init(op);
101 case 1: i = 0x0231;
break;
102 case 2: i = 0x0132;
break;
103 default: i = 0x0213;
break;
106 IOD((
"iounit_get_area(%08lx,%d[%d])=", vaddr, size, npages));
109 rotor = iounit->
rotor[j - 1];
113 if (scan + npages > limit) {
114 if (limit != rotor) {
116 scan = iounit->
limit[j - 1];
121 panic(
"iounit_get_area: Couldn't find free iopte slots for (%08lx,%d)\n", vaddr, size);
124 for (k = 1, scan++; k < npages; k++)
131 for (k = 0; k < npages; k++, iopte =
__iopte(
iopte_val(iopte) + 0x100), scan++) {
135 IOD((
"%08lx\n", vaddr));
139 static __u32 iounit_get_scsi_one(
struct device *
dev,
char *vaddr,
unsigned long len)
145 ret = iounit_get_area(iounit, (
unsigned long)vaddr, len);
146 spin_unlock_irqrestore(&iounit->
lock, flags);
159 sg->
dma_address = iounit_get_area(iounit, (
unsigned long) sg_virt(sg), sg->
length);
160 sg->dma_length = sg->
length;
163 spin_unlock_irqrestore(&iounit->
lock, flags);
166 static void iounit_release_scsi_one(
struct device *dev,
__u32 vaddr,
unsigned long len)
174 IOD((
"iounit_release %08lx-%08lx\n", (
long)vaddr, (
long)len+vaddr));
175 for (len += vaddr; vaddr < len; vaddr++)
177 spin_unlock_irqrestore(&iounit->
lock, flags);
180 static void iounit_release_scsi_sgl(
struct device *dev,
struct scatterlist *sg,
int sz)
184 unsigned long vaddr, len;
191 IOD((
"iounit_release %08lx-%08lx\n", (
long)vaddr, (
long)len+vaddr));
192 for (len += vaddr; vaddr < len; vaddr++)
196 spin_unlock_irqrestore(&iounit->
lock, flags);
200 static int iounit_map_dma_area(
struct device *dev,
dma_addr_t *pba,
unsigned long va,
unsigned long addr,
int len)
239 static void iounit_unmap_dma_area(
struct device *dev,
unsigned long addr,
int len)
246 .get_scsi_one = iounit_get_scsi_one,
247 .get_scsi_sgl = iounit_get_scsi_sgl,
248 .release_scsi_one = iounit_release_scsi_one,
249 .release_scsi_sgl = iounit_release_scsi_sgl,
251 .map_dma_area = iounit_map_dma_area,
252 .unmap_dma_area = iounit_unmap_dma_area,