1 /*- 2 * Copyright (c) 1991 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * William Jolitz. 7 * 8 * %sccs.include.redist.c% 9 * 10 * @(#)isa.c 7.4 (Berkeley) 10/11/92 11 */ 12 13 /* 14 * code to manage AT bus 15 */ 16 17 #include <sys/param.h> 18 #include <sys/systm.h> 19 #include <sys/conf.h> 20 #include <sys/file.h> 21 #include <sys/buf.h> 22 #include <sys/uio.h> 23 #include <sys/syslog.h> 24 25 #include <machine/segments.h> 26 #include <i386/isa/isa_device.h> 27 #include <i386/isa/icu.h> 28 #include <vm/vm.h> 29 30 /* 31 * Configure all ISA devices 32 */ 33 isa_configure() { 34 struct isa_device *dvp; 35 struct isa_driver *dp; 36 37 splhigh(); 38 INTREN(IRQ_SLAVE); 39 for (dvp = isa_devtab_bio; config_isadev(dvp,&biomask); dvp++); 40 for (dvp = isa_devtab_tty; config_isadev(dvp,&ttymask); dvp++); 41 for (dvp = isa_devtab_net; config_isadev(dvp,&netmask); dvp++); 42 for (dvp = isa_devtab_null; config_isadev(dvp,0); dvp++); 43 #include "sl.h" 44 #if NSL > 0 45 netmask |= ttymask; 46 ttymask |= netmask; 47 #endif 48 /* biomask |= ttymask ; can some tty devices use buffers? */ 49 printf("biomask %x ttymask %x netmask %x\n", biomask, ttymask, netmask); 50 splnone(); 51 } 52 53 /* 54 * Configure an ISA device. 55 */ 56 config_isadev(isdp, mp) 57 struct isa_device *isdp; 58 int *mp; 59 { 60 struct isa_driver *dp; 61 62 if (dp = isdp->id_driver) { 63 if (isdp->id_maddr) { 64 extern int atdevbase; 65 66 isdp->id_maddr -= 0xa0000; 67 isdp->id_maddr += atdevbase; 68 } 69 isdp->id_alive = (*dp->probe)(isdp); 70 if (isdp->id_alive) { 71 printf("%s%d", dp->name, isdp->id_unit); 72 (*dp->attach)(isdp); 73 printf(" at 0x%x ", isdp->id_iobase); 74 if(isdp->id_irq) { 75 int intrno; 76 77 intrno = ffs(isdp->id_irq)-1; 78 printf("irq %d ", intrno); 79 INTREN(isdp->id_irq); 80 if(mp)INTRMASK(*mp,isdp->id_irq); 81 setidt(ICU_OFFSET+intrno, isdp->id_intr, 82 SDT_SYS386IGT, SEL_KPL); 83 } 84 if (isdp->id_drq != -1) printf("drq %d ", isdp->id_drq); 85 printf("on isa\n"); 86 } 87 return (1); 88 } else return(0); 89 } 90 91 #define IDTVEC(name) __CONCAT(X,name) 92 /* default interrupt vector table */ 93 extern IDTVEC(intr0), IDTVEC(intr1), IDTVEC(intr2), IDTVEC(intr3), 94 IDTVEC(intr4), IDTVEC(intr5), IDTVEC(intr6), IDTVEC(intr7), 95 IDTVEC(intr8), IDTVEC(intr9), IDTVEC(intr10), IDTVEC(intr11), 96 IDTVEC(intr12), IDTVEC(intr13), IDTVEC(intr14), IDTVEC(intr15); 97 98 /* 99 * Fill in default interrupt table (in case of spuruious interrupt 100 * during configuration of kernel, setup interrupt control unit 101 */ 102 isa_defaultirq() { 103 104 /* first icu */ 105 setidt(32, &IDTVEC(intr0), SDT_SYS386IGT, SEL_KPL); 106 setidt(33, &IDTVEC(intr1), SDT_SYS386IGT, SEL_KPL); 107 setidt(34, &IDTVEC(intr2), SDT_SYS386IGT, SEL_KPL); 108 setidt(35, &IDTVEC(intr3), SDT_SYS386IGT, SEL_KPL); 109 setidt(36, &IDTVEC(intr4), SDT_SYS386IGT, SEL_KPL); 110 setidt(37, &IDTVEC(intr5), SDT_SYS386IGT, SEL_KPL); 111 setidt(38, &IDTVEC(intr6), SDT_SYS386IGT, SEL_KPL); 112 setidt(39, &IDTVEC(intr7), SDT_SYS386IGT, SEL_KPL); 113 114 /* second icu */ 115 setidt(40, &IDTVEC(intr8), SDT_SYS386IGT, SEL_KPL); 116 setidt(41, &IDTVEC(intr9), SDT_SYS386IGT, SEL_KPL); 117 setidt(42, &IDTVEC(intr10), SDT_SYS386IGT, SEL_KPL); 118 setidt(43, &IDTVEC(intr11), SDT_SYS386IGT, SEL_KPL); 119 setidt(44, &IDTVEC(intr12), SDT_SYS386IGT, SEL_KPL); 120 setidt(45, &IDTVEC(intr13), SDT_SYS386IGT, SEL_KPL); 121 setidt(46, &IDTVEC(intr14), SDT_SYS386IGT, SEL_KPL); 122 setidt(47, &IDTVEC(intr15), SDT_SYS386IGT, SEL_KPL); 123 124 /* initialize 8259's */ 125 outb(0xf1,0); 126 outb(0x20,0x11); 127 outb(0x21,32); 128 outb(0x21,4); 129 outb(0x21,1); 130 outb(0x21,0xff); 131 132 outb(0xa0,0x11); 133 outb(0xa1,40); 134 outb(0xa1,2); 135 outb(0xa1,1); 136 outb(0xa1,0xff); 137 } 138 139 /* stuff needed for virtual to physical calculations */ 140 141 struct buf *dma_bounce[8]; 142 #define MAXDMASZ 512 143 144 /* XXX temporary crud */ 145 kernel_space(x) 146 unsigned long x; 147 { 148 if (x >= KERNBASE) return 1; 149 else return 0; 150 } 151 152 153 /****************************************************************************/ 154 /* at_dma */ 155 /* set up DMA read/write operation and virtual address addr for nbytes */ 156 /****************************************************************************/ 157 at_dma(read,addr,nbytes, chan) 158 int read; 159 unsigned long addr; 160 int nbytes; 161 { 162 unsigned long phys; 163 int s,raw; 164 caddr_t bounce; 165 166 if (kernel_space(addr)) raw = 0; 167 else raw = 1; 168 169 if(raw) { 170 if (dma_bounce[chan] == 0) 171 dma_bounce[chan] = geteblk(MAXDMASZ); 172 bounce = dma_bounce[chan]->b_un.b_addr; 173 } 174 175 /* copy bounce buffer on write */ 176 if (raw && !read) bcopy(addr,bounce,nbytes); 177 178 /* Set read/write bytes */ 179 if (read) { 180 outb(0xC,0x46); outb(0xB,0x46); 181 } else { 182 outb(0xC,0x4A); outb(0xB,0x4A); 183 } 184 /* Send start address */ 185 if (raw) phys = (unsigned long) bounce; 186 else phys = addr; 187 /* translate to physical */ 188 phys = pmap_extract(kernel_pmap, (vm_offset_t)phys); 189 outb(0x4,phys & 0xFF); 190 outb(0x4,(phys>>8) & 0xFF); 191 outb(0x81,(phys>>16) & 0xFF); 192 /* Send count */ 193 nbytes--; 194 outb(0x5,nbytes & 0xFF); 195 outb(0x5,(nbytes>>8) & 0xFF); 196 /* set channel 2 */ 197 outb(0x0A,chan); 198 } 199 200 /* 201 * Handle a NMI, possibly a machine check. 202 * return true to panic system, false to ignore. 203 */ 204 isa_nmi(cd) { 205 206 log(LOG_CRIT, "\nNMI port 61 %x, port 70 %x\n", inb(0x61), inb(0x70)); 207 return(0); 208 } 209 210 /* 211 * Caught a stray interrupt, notify 212 */ 213 isa_strayintr(d) { 214 215 /* for some reason, we get bursts of intr #7, even if not enabled! */ 216 log(LOG_ERR,"ISA strayintr %d", ffs(d)-1); 217 } 218