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.1 (Berkeley) 05/09/91 11 */ 12 13 /* 14 * code to manage AT bus 15 */ 16 17 #include "param.h" 18 #include "systm.h" 19 #include "conf.h" 20 #include "file.h" 21 #include "buf.h" 22 #include "uio.h" 23 #include "syslog.h" 24 #include "machine/segments.h" 25 #include "i386/isa/isa_device.h" 26 #include "i386/isa/icu.h" 27 28 /* 29 * Configure all ISA devices 30 */ 31 isa_configure() { 32 struct isa_device *dvp; 33 struct isa_driver *dp; 34 35 splhigh(); 36 INTREN(IRQ_SLAVE); 37 for (dvp = isa_devtab_bio; config_isadev(dvp,&biomask); dvp++); 38 for (dvp = isa_devtab_tty; config_isadev(dvp,&ttymask); dvp++); 39 for (dvp = isa_devtab_net; config_isadev(dvp,&netmask); dvp++); 40 for (dvp = isa_devtab_null; config_isadev(dvp,0); dvp++); 41 #include "sl.h" 42 #if NSL > 0 43 netmask |= ttymask; 44 ttymask |= netmask; 45 #endif 46 /* biomask |= ttymask ; can some tty devices use buffers? */ 47 printf("biomask %x ttymask %x netmask %x\n", biomask, ttymask, netmask); 48 splnone(); 49 } 50 51 /* 52 * Configure an ISA device. 53 */ 54 config_isadev(isdp, mp) 55 struct isa_device *isdp; 56 int *mp; 57 { 58 struct isa_driver *dp; 59 60 if (dp = isdp->id_driver) { 61 if (isdp->id_maddr) { 62 extern int atdevbase; 63 64 isdp->id_maddr -= 0xa0000; 65 isdp->id_maddr += atdevbase; 66 } 67 isdp->id_alive = (*dp->probe)(isdp); 68 if (isdp->id_alive) { 69 printf("%s%d", dp->name, isdp->id_unit); 70 (*dp->attach)(isdp); 71 printf(" at 0x%x ", isdp->id_iobase); 72 if(isdp->id_irq) { 73 int intrno; 74 75 intrno = ffs(isdp->id_irq)-1; 76 printf("irq %d ", intrno); 77 INTREN(isdp->id_irq); 78 if(mp)INTRMASK(*mp,isdp->id_irq); 79 setidt(ICU_OFFSET+intrno, isdp->id_intr, 80 SDT_SYS386IGT, SEL_KPL); 81 } 82 if (isdp->id_drq != -1) printf("drq %d ", isdp->id_drq); 83 printf("on isa\n"); 84 } 85 return (1); 86 } else return(0); 87 } 88 89 #define IDTVEC(name) __CONCAT(X,name) 90 /* default interrupt vector table */ 91 extern IDTVEC(intr0), IDTVEC(intr1), IDTVEC(intr2), IDTVEC(intr3), 92 IDTVEC(intr4), IDTVEC(intr5), IDTVEC(intr6), IDTVEC(intr7), 93 IDTVEC(intr8), IDTVEC(intr9), IDTVEC(intr10), IDTVEC(intr11), 94 IDTVEC(intr12), IDTVEC(intr13), IDTVEC(intr14), IDTVEC(intr15); 95 96 /* 97 * Fill in default interrupt table (in case of spuruious interrupt 98 * during configuration of kernel, setup interrupt control unit 99 */ 100 isa_defaultirq() { 101 102 /* first icu */ 103 setidt(32, &IDTVEC(intr0), SDT_SYS386IGT, SEL_KPL); 104 setidt(33, &IDTVEC(intr1), SDT_SYS386IGT, SEL_KPL); 105 setidt(34, &IDTVEC(intr2), SDT_SYS386IGT, SEL_KPL); 106 setidt(35, &IDTVEC(intr3), SDT_SYS386IGT, SEL_KPL); 107 setidt(36, &IDTVEC(intr4), SDT_SYS386IGT, SEL_KPL); 108 setidt(37, &IDTVEC(intr5), SDT_SYS386IGT, SEL_KPL); 109 setidt(38, &IDTVEC(intr6), SDT_SYS386IGT, SEL_KPL); 110 setidt(39, &IDTVEC(intr7), SDT_SYS386IGT, SEL_KPL); 111 112 /* second icu */ 113 setidt(40, &IDTVEC(intr8), SDT_SYS386IGT, SEL_KPL); 114 setidt(41, &IDTVEC(intr9), SDT_SYS386IGT, SEL_KPL); 115 setidt(42, &IDTVEC(intr10), SDT_SYS386IGT, SEL_KPL); 116 setidt(43, &IDTVEC(intr11), SDT_SYS386IGT, SEL_KPL); 117 setidt(44, &IDTVEC(intr12), SDT_SYS386IGT, SEL_KPL); 118 setidt(45, &IDTVEC(intr13), SDT_SYS386IGT, SEL_KPL); 119 setidt(46, &IDTVEC(intr14), SDT_SYS386IGT, SEL_KPL); 120 setidt(47, &IDTVEC(intr15), SDT_SYS386IGT, SEL_KPL); 121 122 /* initialize 8259's */ 123 outb(0xf1,0); 124 outb(0x20,0x11); 125 outb(0x21,32); 126 outb(0x21,4); 127 outb(0x21,1); 128 outb(0x21,0xff); 129 130 outb(0xa0,0x11); 131 outb(0xa1,40); 132 outb(0xa1,2); 133 outb(0xa1,1); 134 outb(0xa1,0xff); 135 } 136 137 /* stuff needed for virtual to physical calculations */ 138 extern char Sysbase; 139 static unsigned long sbase = (unsigned long) &Sysbase; 140 141 struct buf *dma_bounce[8]; 142 #define MAXDMASZ 512 143 144 /* XXX temporary */ 145 kernel_space(x) 146 unsigned long x; 147 { 148 if ((x >= sbase) & (x < sbase + 0x800000)) 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(pmap_kernel(), (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