1 /* 2 * code to manage AT bus 3 * @(#)isa.c 1.1 (Berkeley) 11/08/90 4 */ 5 6 #include "param.h" 7 #include "systm.h" 8 #include "conf.h" 9 #include "file.h" 10 #include "dir.h" 11 #include "user.h" 12 #include "buf.h" 13 #include "vm.h" 14 #include "uio.h" 15 #include "machine/pte.h" 16 17 /* stuff needed for virtual to physical calculations */ 18 extern char Sysbase; 19 static unsigned long sbase = (unsigned long) &Sysbase; 20 21 struct buf *dma_bounce[8]; 22 #define MAXDMASZ 512 23 24 /* XXX temporary */ 25 kernel_space(x) 26 unsigned long x; 27 { 28 if ((x >= sbase) & (x < sbase + 0x800000)) return 1; 29 else return 0; 30 } 31 32 33 /****************************************************************************/ 34 /* at_dma */ 35 /* set up DMA read/write operation and virtual address addr for nbytes */ 36 /****************************************************************************/ 37 at_dma(read,addr,nbytes, chan) 38 int read; 39 unsigned long addr; 40 int nbytes; 41 { 42 unsigned long phys; 43 int s,raw; 44 caddr_t bounce; 45 46 if (kernel_space(addr)) raw = 0; 47 else raw = 1; 48 49 if(raw) { 50 if (dma_bounce[chan] == 0) 51 dma_bounce[chan] = geteblk(MAXDMASZ); 52 bounce = dma_bounce[chan]->b_un.b_addr; 53 } 54 55 /* copy bounce buffer on write */ 56 if (raw && !read) bcopy(addr,bounce,nbytes); 57 58 /* Set read/write bytes */ 59 if (read) { 60 outb(0xC,0x46); outb(0xB,0x46); 61 } else { 62 outb(0xC,0x4A); outb(0xB,0x4A); 63 } 64 /* Send start address */ 65 if (raw) phys = (unsigned long) bounce; 66 else phys = addr; 67 /* translate to physical */ 68 phys = phys - sbase; 69 outb(0x4,phys & 0xFF); 70 outb(0x4,(phys>>8) & 0xFF); 71 outb(0x81,(phys>>16) & 0xFF); 72 /* Send count */ 73 nbytes--; 74 outb(0x5,nbytes & 0xFF); 75 outb(0x5,(nbytes>>8) & 0xFF); 76 /* set channel 2 */ 77 outb(0x0A,chan); 78 } 79