--- Net2/arch/i386/isa/isa.c 2018/04/24 18:06:58 1.1.1.3 +++ Net2/arch/i386/isa/isa.c 2018/04/24 18:11:53 1.1.1.4 @@ -35,10 +35,16 @@ * * @(#)isa.c 7.2 (Berkeley) 5/13/91 */ -static char rcsid[] = "$Header: /var/lib/cvsd/net2/Net2/arch/i386/isa/isa.c,v 1.1.1.3 2018/04/24 18:06:58 root Exp $"; +static char rcsid[] = "$Header: /var/lib/cvsd/net2/Net2/arch/i386/isa/isa.c,v 1.1.1.4 2018/04/24 18:11:53 root Exp $"; /* * code to manage AT bus + * + * 92/08/18 Frank P. MacLachlan (fpm@crash.cts.com): + * Fixed uninitialized variable problem and added code to deal + * with DMA page boundaries in isa_dmarangecheck(). Fixed word + * mode DMA count compution and reorganized DMA setup code in + * isa_dmastart() */ #include "param.h" @@ -58,6 +64,22 @@ static char rcsid[] = "$Header: /var/lib #include "i386/isa/ic/i8237.h" #include "i386/isa/ic/i8042.h" +/* +** Register definitions for DMA controller 1 (channels 0..3): +*/ +#define DMA1_CHN(c) (IO_DMA1 + 1*(2*(c))) /* addr reg for channel c */ +#define DMA1_SMSK (IO_DMA1 + 1*10) /* single mask register */ +#define DMA1_MODE (IO_DMA1 + 1*11) /* mode register */ +#define DMA1_FFC (IO_DMA1 + 1*12) /* clear first/last FF */ + +/* +** Register definitions for DMA controller 2 (channels 4..7): +*/ +#define DMA2_CHN(c) (IO_DMA1 + 2*(2*(c))) /* addr reg for channel c */ +#define DMA2_SMSK (IO_DMA2 + 2*10) /* single mask register */ +#define DMA2_MODE (IO_DMA2 + 2*11) /* mode register */ +#define DMA2_FFC (IO_DMA2 + 2*12) /* clear first/last FF */ + int config_isadev(struct isa_device *, u_short *); #ifdef notyet struct rlist *isa_iomem; @@ -150,7 +172,7 @@ config_isadev(isdp, mp) return (1); } else return(0); } -#else +#else /* notyet */ /* * Configure all ISA devices */ @@ -193,25 +215,40 @@ config_isadev(isdp, mp) isdp->id_alive = (*dp->probe)(isdp); if (isdp->id_alive) { printf("%s%d", dp->name, isdp->id_unit); + printf(" at 0x%x", isdp->id_iobase); + if ((isdp->id_iobase + isdp->id_alive - 1) != + isdp->id_iobase) + printf("-0x%x", + isdp->id_iobase + isdp->id_alive - 1); + printf(" "); + if(isdp->id_irq) + printf("irq %d ", ffs(isdp->id_irq)-1); + if (isdp->id_drq != -1) + printf("drq %d ", isdp->id_drq); + if (isdp->id_maddr != 0) + printf("maddr 0x%x ", kvtop(isdp->id_maddr)); + if (isdp->id_msize != 0) + printf("msize %d ", isdp->id_msize); + if (isdp->id_flags != 0) + printf("flags 0x%x ", isdp->id_flags); + printf("on isa\n"); + (*dp->attach)(isdp); - printf(" at 0x%x ", isdp->id_iobase); if(isdp->id_irq) { int intrno; intrno = ffs(isdp->id_irq)-1; - printf("irq %d ", intrno); INTREN(isdp->id_irq); - if(mp)INTRMASK(*mp,isdp->id_irq); + if(mp) + INTRMASK(*mp,isdp->id_irq); setidt(ICU_OFFSET+intrno, isdp->id_intr, SDT_SYS386IGT, SEL_KPL); } - if (isdp->id_drq != -1) printf("drq %d ", isdp->id_drq); - printf("on isa\n"); } return (1); } else return(0); } -#endif +#endif /* (!) notyet */ #define IDTVEC(name) __CONCAT(X,name) /* default interrupt vector table entries */ @@ -278,21 +315,18 @@ static short dmapageport[8] = * external dma control by a board. */ void isa_dmacascade(unsigned chan) -{ int modeport; - +{ if (chan > 7) panic("isa_dmacascade: impossible request"); /* set dma channel mode, and set dma channel mode */ - if ((chan & 4) == 0) - modeport = IO_DMA1 + 0xb; - else - modeport = IO_DMA2 + 0x16; - outb(modeport, DMA37MD_CASCADE | (chan & 3)); - if ((chan & 4) == 0) - outb(modeport - 1, chan & 3); - else - outb(modeport - 2, chan & 3); + if ((chan & 4) == 0) { + outb(DMA1_MODE, DMA37MD_CASCADE | chan); + outb(DMA1_SMSK, chan); + } else { + outb(DMA2_MODE, DMA37MD_CASCADE | (chan & 3)); + outb(DMA2_SMSK, chan & 3); + } } /* @@ -301,13 +335,15 @@ void isa_dmacascade(unsigned chan) */ void isa_dmastart(int flags, caddr_t addr, unsigned nbytes, unsigned chan) { vm_offset_t phys; - int modeport, waport, mskport; + int waport; caddr_t newaddr; - if (chan > 7 || nbytes > (1<<16)) + if ( chan > 7 + || (chan < 4 && nbytes > (1<<16)) + || (chan >= 4 && (nbytes > (1<<17) || (u_int)addr & 1))) panic("isa_dmastart: impossible request"); - if (isa_dmarangecheck(addr, nbytes)) { + if (isa_dmarangecheck(addr, nbytes, chan)) { if (dma_bounce[chan] == 0) dma_bounce[chan] = /*(caddr_t)malloc(MAXDMASZ, M_TEMP, M_WAITOK);*/ @@ -325,48 +361,56 @@ void isa_dmastart(int flags, caddr_t add /* translate to physical */ phys = pmap_extract(pmap_kernel(), (vm_offset_t)addr); - /* set dma channel mode, and reset address ff */ - if ((chan & 4) == 0) - modeport = IO_DMA1 + 0xb; - else - modeport = IO_DMA2 + 0x16; - if (flags & B_READ) - outb(modeport, DMA37MD_SINGLE|DMA37MD_WRITE|(chan&3)); - else - outb(modeport, DMA37MD_SINGLE|DMA37MD_READ|(chan&3)); - if ((chan & 4) == 0) - outb(modeport + 1, 0); - else - outb(modeport + 2, 0); - - /* send start address */ if ((chan & 4) == 0) { - waport = IO_DMA1 + (chan<<1); + /* + * Program one of DMA channels 0..3. These are + * byte mode channels. + */ + /* set dma channel mode, and reset address ff */ + if (flags & B_READ) + outb(DMA1_MODE, DMA37MD_SINGLE|DMA37MD_WRITE|chan); + else + outb(DMA1_MODE, DMA37MD_SINGLE|DMA37MD_READ|chan); + outb(DMA1_FFC, 0); + + /* send start address */ + waport = DMA1_CHN(chan); outb(waport, phys); outb(waport, phys>>8); - } else { - waport = IO_DMA2 + ((chan - 4)<<2); - outb(waport, phys>>1); - outb(waport, phys>>9); - } - outb(dmapageport[chan], phys>>16); + outb(dmapageport[chan], phys>>16); - /* send count */ - if ((chan & 4) == 0) { + /* send count */ outb(waport + 1, --nbytes); outb(waport + 1, nbytes>>8); + + /* unmask channel */ + outb(DMA1_SMSK, chan); } else { - nbytes <<= 1; + /* + * Program one of DMA channels 4..7. These are + * word mode channels. + */ + /* set dma channel mode, and reset address ff */ + if (flags & B_READ) + outb(DMA2_MODE, DMA37MD_SINGLE|DMA37MD_WRITE|(chan&3)); + else + outb(DMA2_MODE, DMA37MD_SINGLE|DMA37MD_READ|(chan&3)); + outb(DMA2_FFC, 0); + + /* send start address */ + waport = DMA2_CHN(chan - 4); + outb(waport, phys>>1); + outb(waport, phys>>9); + outb(dmapageport[chan], phys>>16); + + /* send count */ + nbytes >>= 1; outb(waport + 2, --nbytes); outb(waport + 2, nbytes>>8); - } - /* unmask channel */ - if ((chan & 4) == 0) - mskport = IO_DMA1 + 0x0a; - else - mskport = IO_DMA2 + 0x14; - outb(mskport, chan & 3); + /* unmask channel */ + outb(DMA2_SMSK, chan & 3); + } } void isa_dmadone(int flags, caddr_t addr, int nbytes, int chan) @@ -382,12 +426,14 @@ void isa_dmadone(int flags, caddr_t addr /* * Check for problems with the address range of a DMA transfer - * (non-contiguous physical pages, outside of bus address space). + * (non-contiguous physical pages, outside of bus address space, + * crossing DMA page boundaries). * Return true if special handling needed. */ -isa_dmarangecheck(caddr_t va, unsigned length) { - vm_offset_t phys, priorpage, endva; +isa_dmarangecheck(caddr_t va, unsigned length, unsigned chan) { + vm_offset_t phys, priorpage = 0, endva; + u_int dma_pgmsk = (chan & 4) ? ~(128*1024-1) : ~(64*1024-1); endva = (vm_offset_t)round_page(va + length); for (; va < (caddr_t) endva ; va += NBPG) { @@ -397,8 +443,13 @@ isa_dmarangecheck(caddr_t va, unsigned l panic("isa_dmacheck: no physical page present"); if (phys > ISARAM_END) return (1); - if (priorpage && priorpage + NBPG != phys) - return (1); + if (priorpage) { + if (priorpage + NBPG != phys) + return (1); + /* check if crossing a DMA page boundary */ + if (((u_int)priorpage ^ (u_int)phys) & dma_pgmsk) + return (1); + } priorpage = phys; } return (0); @@ -461,11 +512,23 @@ isa_nmi(cd) { */ isa_strayintr(d) { -#ifdef notdef /* DON'T BOTHER FOR NOW! */ /* for some reason, we get bursts of intr #7, even if not enabled! */ - log(LOG_ERR,"ISA strayintr %x", d); -#endif + /* + * Well the reason you got bursts of intr #7 is because someone + * raised an interrupt line and dropped it before the 8259 could + * prioritize it. This is documented in the intel data book. This + * means you have BAD hardware! I have changed this so that only + * the first 10 get logged, then it quits logging them, and puts + * out a special message. rgrimes 3/25/1993 + */ + extern u_long isa_stray_intrcnt; + + isa_stray_intrcnt++; + if (isa_stray_intrcnt <= 10) + log(LOG_ERR,"ISA strayintr %x\n", d); + if (isa_stray_intrcnt == 10) + log(LOG_CRIT,"Too many ISA strayintr not logging any more\n"); } /*