isa.c revision 1.6 1 1.1 cgd /*-
2 1.1 cgd * Copyright (c) 1991 The Regents of the University of California.
3 1.1 cgd * All rights reserved.
4 1.1 cgd *
5 1.1 cgd * This code is derived from software contributed to Berkeley by
6 1.1 cgd * William Jolitz.
7 1.1 cgd *
8 1.1 cgd * Redistribution and use in source and binary forms, with or without
9 1.1 cgd * modification, are permitted provided that the following conditions
10 1.1 cgd * are met:
11 1.1 cgd * 1. Redistributions of source code must retain the above copyright
12 1.1 cgd * notice, this list of conditions and the following disclaimer.
13 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 cgd * notice, this list of conditions and the following disclaimer in the
15 1.1 cgd * documentation and/or other materials provided with the distribution.
16 1.1 cgd * 3. All advertising materials mentioning features or use of this software
17 1.1 cgd * must display the following acknowledgement:
18 1.1 cgd * This product includes software developed by the University of
19 1.1 cgd * California, Berkeley and its contributors.
20 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
21 1.1 cgd * may be used to endorse or promote products derived from this software
22 1.1 cgd * without specific prior written permission.
23 1.1 cgd *
24 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 1.1 cgd * SUCH DAMAGE.
35 1.1 cgd *
36 1.1 cgd * @(#)isa.c 7.2 (Berkeley) 5/13/91
37 1.1 cgd */
38 1.6 deraadt static char rcsid[] = "$Header: /tank/opengrok/rsync2/NetBSD/src/sys/dev/isa/isa.c,v 1.6 1993/04/15 07:57:57 deraadt Exp $";
39 1.1 cgd
40 1.1 cgd /*
41 1.1 cgd * code to manage AT bus
42 1.2 cgd *
43 1.2 cgd * 92/08/18 Frank P. MacLachlan (fpm (at) crash.cts.com):
44 1.2 cgd * Fixed uninitialized variable problem and added code to deal
45 1.2 cgd * with DMA page boundaries in isa_dmarangecheck(). Fixed word
46 1.2 cgd * mode DMA count compution and reorganized DMA setup code in
47 1.2 cgd * isa_dmastart()
48 1.1 cgd */
49 1.1 cgd
50 1.1 cgd #include "param.h"
51 1.1 cgd #include "systm.h"
52 1.1 cgd #include "conf.h"
53 1.1 cgd #include "file.h"
54 1.1 cgd #include "buf.h"
55 1.1 cgd #include "uio.h"
56 1.1 cgd #include "syslog.h"
57 1.1 cgd #include "malloc.h"
58 1.1 cgd #include "rlist.h"
59 1.1 cgd #include "machine/segments.h"
60 1.1 cgd #include "vm/vm.h"
61 1.1 cgd #include "i386/isa/isa_device.h"
62 1.1 cgd #include "i386/isa/isa.h"
63 1.1 cgd #include "i386/isa/icu.h"
64 1.1 cgd #include "i386/isa/ic/i8237.h"
65 1.1 cgd #include "i386/isa/ic/i8042.h"
66 1.1 cgd
67 1.2 cgd /*
68 1.2 cgd ** Register definitions for DMA controller 1 (channels 0..3):
69 1.2 cgd */
70 1.2 cgd #define DMA1_CHN(c) (IO_DMA1 + 1*(2*(c))) /* addr reg for channel c */
71 1.2 cgd #define DMA1_SMSK (IO_DMA1 + 1*10) /* single mask register */
72 1.2 cgd #define DMA1_MODE (IO_DMA1 + 1*11) /* mode register */
73 1.2 cgd #define DMA1_FFC (IO_DMA1 + 1*12) /* clear first/last FF */
74 1.2 cgd
75 1.2 cgd /*
76 1.2 cgd ** Register definitions for DMA controller 2 (channels 4..7):
77 1.2 cgd */
78 1.2 cgd #define DMA2_CHN(c) (IO_DMA1 + 2*(2*(c))) /* addr reg for channel c */
79 1.2 cgd #define DMA2_SMSK (IO_DMA2 + 2*10) /* single mask register */
80 1.2 cgd #define DMA2_MODE (IO_DMA2 + 2*11) /* mode register */
81 1.2 cgd #define DMA2_FFC (IO_DMA2 + 2*12) /* clear first/last FF */
82 1.2 cgd
83 1.1 cgd int config_isadev(struct isa_device *, u_short *);
84 1.6 deraadt void config_attach(struct isa_driver *, struct isa_device *);
85 1.1 cgd
86 1.1 cgd /*
87 1.1 cgd * Configure all ISA devices
88 1.1 cgd */
89 1.1 cgd isa_configure() {
90 1.1 cgd struct isa_device *dvp;
91 1.1 cgd struct isa_driver *dp;
92 1.1 cgd
93 1.1 cgd splhigh();
94 1.1 cgd INTREN(IRQ_SLAVE);
95 1.6 deraadt for (dvp = isa_devtab_tty; config_isadev(dvp,&ttymask); dvp++)
96 1.6 deraadt ;
97 1.6 deraadt for (dvp = isa_devtab_bio; config_isadev(dvp,&biomask); dvp++)
98 1.6 deraadt ;
99 1.6 deraadt for (dvp = isa_devtab_net; config_isadev(dvp,&netmask); dvp++)
100 1.6 deraadt ;
101 1.6 deraadt for (dvp = isa_devtab_null; config_isadev(dvp,0); dvp++)
102 1.6 deraadt ;
103 1.1 cgd #include "sl.h"
104 1.1 cgd #if NSL > 0
105 1.1 cgd netmask |= ttymask;
106 1.1 cgd ttymask |= netmask;
107 1.1 cgd #endif
108 1.1 cgd /* biomask |= ttymask ; can some tty devices use buffers? */
109 1.1 cgd /* printf("biomask %x ttymask %x netmask %x\n", biomask, ttymask, netmask); */
110 1.1 cgd splnone();
111 1.1 cgd }
112 1.1 cgd
113 1.1 cgd /*
114 1.1 cgd * Configure an ISA device.
115 1.1 cgd */
116 1.1 cgd config_isadev(isdp, mp)
117 1.1 cgd struct isa_device *isdp;
118 1.1 cgd u_short *mp;
119 1.1 cgd {
120 1.1 cgd struct isa_driver *dp;
121 1.1 cgd
122 1.1 cgd if (dp = isdp->id_driver) {
123 1.1 cgd if (isdp->id_maddr) {
124 1.1 cgd extern u_int atdevbase;
125 1.1 cgd
126 1.1 cgd isdp->id_maddr -= 0xa0000;
127 1.1 cgd isdp->id_maddr += atdevbase;
128 1.1 cgd }
129 1.1 cgd isdp->id_alive = (*dp->probe)(isdp);
130 1.1 cgd if (isdp->id_alive) {
131 1.1 cgd printf("%s%d", dp->name, isdp->id_unit);
132 1.5 cgd printf(" at 0x%x", isdp->id_iobase);
133 1.5 cgd if ((isdp->id_iobase + isdp->id_alive - 1) !=
134 1.5 cgd isdp->id_iobase)
135 1.5 cgd printf("-0x%x",
136 1.5 cgd isdp->id_iobase + isdp->id_alive - 1);
137 1.5 cgd printf(" ");
138 1.3 deraadt if(isdp->id_irq)
139 1.3 deraadt printf("irq %d ", ffs(isdp->id_irq)-1);
140 1.3 deraadt if (isdp->id_drq != -1)
141 1.3 deraadt printf("drq %d ", isdp->id_drq);
142 1.4 cgd if (isdp->id_maddr != 0)
143 1.4 cgd printf("maddr 0x%x ", kvtop(isdp->id_maddr));
144 1.4 cgd if (isdp->id_msize != 0)
145 1.4 cgd printf("msize %d ", isdp->id_msize);
146 1.4 cgd if (isdp->id_flags != 0)
147 1.4 cgd printf("flags 0x%x ", isdp->id_flags);
148 1.3 deraadt printf("on isa\n");
149 1.3 deraadt
150 1.6 deraadt config_attach(dp, isdp);
151 1.6 deraadt
152 1.1 cgd if(isdp->id_irq) {
153 1.1 cgd int intrno;
154 1.1 cgd
155 1.1 cgd intrno = ffs(isdp->id_irq)-1;
156 1.1 cgd INTREN(isdp->id_irq);
157 1.3 deraadt if(mp)
158 1.3 deraadt INTRMASK(*mp,isdp->id_irq);
159 1.1 cgd setidt(ICU_OFFSET+intrno, isdp->id_intr,
160 1.1 cgd SDT_SYS386IGT, SEL_KPL);
161 1.1 cgd }
162 1.1 cgd }
163 1.1 cgd return (1);
164 1.1 cgd } else return(0);
165 1.1 cgd }
166 1.6 deraadt
167 1.6 deraadt void
168 1.6 deraadt config_attach(struct isa_driver *dp, struct isa_device *isdp)
169 1.6 deraadt {
170 1.6 deraadt extern struct isa_device isa_subdev[];
171 1.6 deraadt struct isa_device *dvp;
172 1.6 deraadt
173 1.6 deraadt if(isdp->id_masunit==-1) {
174 1.6 deraadt (*dp->attach)(isdp);
175 1.6 deraadt return;
176 1.6 deraadt }
177 1.6 deraadt
178 1.6 deraadt if(isdp->id_masunit==0) {
179 1.6 deraadt for(dvp = isa_subdev; dvp->id_driver; dvp++) {
180 1.6 deraadt if (dvp->id_driver != dp)
181 1.6 deraadt continue;
182 1.6 deraadt if (dvp->id_masunit != isdp->id_masunit)
183 1.6 deraadt continue;
184 1.6 deraadt if (dvp->id_physid == -1)
185 1.6 deraadt continue;
186 1.6 deraadt (*dp->attach)(dvp);
187 1.6 deraadt }
188 1.6 deraadt for(dvp = isa_subdev; dvp->id_driver; dvp++) {
189 1.6 deraadt if (dvp->id_driver != dp)
190 1.6 deraadt continue;
191 1.6 deraadt if (dvp->id_masunit != isdp->id_masunit)
192 1.6 deraadt continue;
193 1.6 deraadt if (dvp->id_physid != -1)
194 1.6 deraadt continue;
195 1.6 deraadt (*dp->attach)(dvp);
196 1.6 deraadt }
197 1.6 deraadt return;
198 1.6 deraadt }
199 1.6 deraadt printf("id_masunit has weird value\n");
200 1.6 deraadt }
201 1.6 deraadt
202 1.1 cgd
203 1.1 cgd #define IDTVEC(name) __CONCAT(X,name)
204 1.1 cgd /* default interrupt vector table entries */
205 1.1 cgd extern IDTVEC(intr0), IDTVEC(intr1), IDTVEC(intr2), IDTVEC(intr3),
206 1.1 cgd IDTVEC(intr4), IDTVEC(intr5), IDTVEC(intr6), IDTVEC(intr7),
207 1.1 cgd IDTVEC(intr8), IDTVEC(intr9), IDTVEC(intr10), IDTVEC(intr11),
208 1.1 cgd IDTVEC(intr12), IDTVEC(intr13), IDTVEC(intr14), IDTVEC(intr15);
209 1.1 cgd
210 1.1 cgd static *defvec[16] = {
211 1.1 cgd &IDTVEC(intr0), &IDTVEC(intr1), &IDTVEC(intr2), &IDTVEC(intr3),
212 1.1 cgd &IDTVEC(intr4), &IDTVEC(intr5), &IDTVEC(intr6), &IDTVEC(intr7),
213 1.1 cgd &IDTVEC(intr8), &IDTVEC(intr9), &IDTVEC(intr10), &IDTVEC(intr11),
214 1.1 cgd &IDTVEC(intr12), &IDTVEC(intr13), &IDTVEC(intr14), &IDTVEC(intr15) };
215 1.1 cgd
216 1.1 cgd /* out of range default interrupt vector gate entry */
217 1.1 cgd extern IDTVEC(intrdefault);
218 1.1 cgd
219 1.1 cgd /*
220 1.1 cgd * Fill in default interrupt table (in case of spuruious interrupt
221 1.1 cgd * during configuration of kernel, setup interrupt control unit
222 1.1 cgd */
223 1.1 cgd isa_defaultirq() {
224 1.1 cgd int i;
225 1.1 cgd
226 1.1 cgd /* icu vectors */
227 1.1 cgd for (i = NRSVIDT ; i < NRSVIDT+ICU_LEN ; i++)
228 1.1 cgd setidt(i, defvec[i], SDT_SYS386IGT, SEL_KPL);
229 1.1 cgd
230 1.1 cgd /* out of range vectors */
231 1.1 cgd for (i = NRSVIDT; i < NIDT; i++)
232 1.1 cgd setidt(i, &IDTVEC(intrdefault), SDT_SYS386IGT, SEL_KPL);
233 1.1 cgd
234 1.1 cgd /* clear npx intr latch */
235 1.1 cgd outb(0xf1,0);
236 1.1 cgd
237 1.1 cgd /* initialize 8259's */
238 1.1 cgd outb(IO_ICU1, 0x11); /* reset; program device, four bytes */
239 1.1 cgd outb(IO_ICU1+1, NRSVIDT); /* starting at this vector index */
240 1.1 cgd outb(IO_ICU1+1, 1<<2); /* slave on line 2 */
241 1.1 cgd outb(IO_ICU1+1, 1); /* 8086 mode */
242 1.1 cgd outb(IO_ICU1+1, 0xff); /* leave interrupts masked */
243 1.1 cgd outb(IO_ICU1, 2); /* default to ISR on read */
244 1.1 cgd
245 1.1 cgd outb(IO_ICU2, 0x11); /* reset; program device, four bytes */
246 1.1 cgd outb(IO_ICU2+1, NRSVIDT+8); /* staring at this vector index */
247 1.1 cgd outb(IO_ICU2+1,2); /* my slave id is 2 */
248 1.1 cgd outb(IO_ICU2+1,1); /* 8086 mode */
249 1.1 cgd outb(IO_ICU2+1, 0xff); /* leave interrupts masked */
250 1.1 cgd outb(IO_ICU2, 2); /* default to ISR on read */
251 1.1 cgd }
252 1.1 cgd
253 1.1 cgd /* region of physical memory known to be contiguous */
254 1.1 cgd vm_offset_t isaphysmem;
255 1.1 cgd static caddr_t dma_bounce[8]; /* XXX */
256 1.1 cgd static char bounced[8]; /* XXX */
257 1.1 cgd #define MAXDMASZ 512 /* XXX */
258 1.1 cgd
259 1.1 cgd /* high byte of address is stored in this port for i-th dma channel */
260 1.1 cgd static short dmapageport[8] =
261 1.1 cgd { 0x87, 0x83, 0x81, 0x82, 0x8f, 0x8b, 0x89, 0x8a };
262 1.1 cgd
263 1.1 cgd /*
264 1.1 cgd * isa_dmacascade(): program 8237 DMA controller channel to accept
265 1.1 cgd * external dma control by a board.
266 1.1 cgd */
267 1.1 cgd void isa_dmacascade(unsigned chan)
268 1.2 cgd {
269 1.1 cgd if (chan > 7)
270 1.1 cgd panic("isa_dmacascade: impossible request");
271 1.1 cgd
272 1.1 cgd /* set dma channel mode, and set dma channel mode */
273 1.2 cgd if ((chan & 4) == 0) {
274 1.2 cgd outb(DMA1_MODE, DMA37MD_CASCADE | chan);
275 1.2 cgd outb(DMA1_SMSK, chan);
276 1.2 cgd } else {
277 1.2 cgd outb(DMA2_MODE, DMA37MD_CASCADE | (chan & 3));
278 1.2 cgd outb(DMA2_SMSK, chan & 3);
279 1.2 cgd }
280 1.1 cgd }
281 1.1 cgd
282 1.1 cgd /*
283 1.1 cgd * isa_dmastart(): program 8237 DMA controller channel, avoid page alignment
284 1.1 cgd * problems by using a bounce buffer.
285 1.1 cgd */
286 1.1 cgd void isa_dmastart(int flags, caddr_t addr, unsigned nbytes, unsigned chan)
287 1.1 cgd { vm_offset_t phys;
288 1.2 cgd int waport;
289 1.1 cgd caddr_t newaddr;
290 1.1 cgd
291 1.2 cgd if ( chan > 7
292 1.2 cgd || (chan < 4 && nbytes > (1<<16))
293 1.2 cgd || (chan >= 4 && (nbytes > (1<<17) || (u_int)addr & 1)))
294 1.1 cgd panic("isa_dmastart: impossible request");
295 1.1 cgd
296 1.2 cgd if (isa_dmarangecheck(addr, nbytes, chan)) {
297 1.1 cgd if (dma_bounce[chan] == 0)
298 1.1 cgd dma_bounce[chan] =
299 1.1 cgd /*(caddr_t)malloc(MAXDMASZ, M_TEMP, M_WAITOK);*/
300 1.1 cgd (caddr_t) isaphysmem + NBPG*chan;
301 1.1 cgd bounced[chan] = 1;
302 1.1 cgd newaddr = dma_bounce[chan];
303 1.1 cgd *(int *) newaddr = 0; /* XXX */
304 1.1 cgd
305 1.1 cgd /* copy bounce buffer on write */
306 1.1 cgd if (!(flags & B_READ))
307 1.1 cgd bcopy(addr, newaddr, nbytes);
308 1.1 cgd addr = newaddr;
309 1.1 cgd }
310 1.1 cgd
311 1.1 cgd /* translate to physical */
312 1.1 cgd phys = pmap_extract(pmap_kernel(), (vm_offset_t)addr);
313 1.1 cgd
314 1.2 cgd if ((chan & 4) == 0) {
315 1.2 cgd /*
316 1.2 cgd * Program one of DMA channels 0..3. These are
317 1.2 cgd * byte mode channels.
318 1.2 cgd */
319 1.2 cgd /* set dma channel mode, and reset address ff */
320 1.2 cgd if (flags & B_READ)
321 1.2 cgd outb(DMA1_MODE, DMA37MD_SINGLE|DMA37MD_WRITE|chan);
322 1.2 cgd else
323 1.2 cgd outb(DMA1_MODE, DMA37MD_SINGLE|DMA37MD_READ|chan);
324 1.2 cgd outb(DMA1_FFC, 0);
325 1.1 cgd
326 1.2 cgd /* send start address */
327 1.2 cgd waport = DMA1_CHN(chan);
328 1.1 cgd outb(waport, phys);
329 1.1 cgd outb(waport, phys>>8);
330 1.2 cgd outb(dmapageport[chan], phys>>16);
331 1.2 cgd
332 1.2 cgd /* send count */
333 1.2 cgd outb(waport + 1, --nbytes);
334 1.2 cgd outb(waport + 1, nbytes>>8);
335 1.2 cgd
336 1.2 cgd /* unmask channel */
337 1.2 cgd outb(DMA1_SMSK, chan);
338 1.1 cgd } else {
339 1.2 cgd /*
340 1.2 cgd * Program one of DMA channels 4..7. These are
341 1.2 cgd * word mode channels.
342 1.2 cgd */
343 1.2 cgd /* set dma channel mode, and reset address ff */
344 1.2 cgd if (flags & B_READ)
345 1.2 cgd outb(DMA2_MODE, DMA37MD_SINGLE|DMA37MD_WRITE|(chan&3));
346 1.2 cgd else
347 1.2 cgd outb(DMA2_MODE, DMA37MD_SINGLE|DMA37MD_READ|(chan&3));
348 1.2 cgd outb(DMA2_FFC, 0);
349 1.2 cgd
350 1.2 cgd /* send start address */
351 1.2 cgd waport = DMA2_CHN(chan - 4);
352 1.1 cgd outb(waport, phys>>1);
353 1.1 cgd outb(waport, phys>>9);
354 1.2 cgd outb(dmapageport[chan], phys>>16);
355 1.1 cgd
356 1.2 cgd /* send count */
357 1.2 cgd nbytes >>= 1;
358 1.1 cgd outb(waport + 2, --nbytes);
359 1.1 cgd outb(waport + 2, nbytes>>8);
360 1.2 cgd
361 1.2 cgd /* unmask channel */
362 1.2 cgd outb(DMA2_SMSK, chan & 3);
363 1.1 cgd }
364 1.1 cgd }
365 1.1 cgd
366 1.1 cgd void isa_dmadone(int flags, caddr_t addr, int nbytes, int chan)
367 1.1 cgd {
368 1.1 cgd
369 1.1 cgd /* copy bounce buffer on read */
370 1.1 cgd /*if ((flags & (B_PHYS|B_READ)) == (B_PHYS|B_READ))*/
371 1.1 cgd if (bounced[chan]) {
372 1.1 cgd bcopy(dma_bounce[chan], addr, nbytes);
373 1.1 cgd bounced[chan] = 0;
374 1.1 cgd }
375 1.1 cgd }
376 1.1 cgd
377 1.1 cgd /*
378 1.1 cgd * Check for problems with the address range of a DMA transfer
379 1.2 cgd * (non-contiguous physical pages, outside of bus address space,
380 1.2 cgd * crossing DMA page boundaries).
381 1.1 cgd * Return true if special handling needed.
382 1.1 cgd */
383 1.1 cgd
384 1.2 cgd isa_dmarangecheck(caddr_t va, unsigned length, unsigned chan) {
385 1.2 cgd vm_offset_t phys, priorpage = 0, endva;
386 1.2 cgd u_int dma_pgmsk = (chan & 4) ? ~(128*1024-1) : ~(64*1024-1);
387 1.1 cgd
388 1.1 cgd endva = (vm_offset_t)round_page(va + length);
389 1.1 cgd for (; va < (caddr_t) endva ; va += NBPG) {
390 1.1 cgd phys = trunc_page(pmap_extract(pmap_kernel(), (vm_offset_t)va));
391 1.1 cgd #define ISARAM_END RAM_END
392 1.1 cgd if (phys == 0)
393 1.1 cgd panic("isa_dmacheck: no physical page present");
394 1.1 cgd if (phys > ISARAM_END)
395 1.1 cgd return (1);
396 1.2 cgd if (priorpage) {
397 1.2 cgd if (priorpage + NBPG != phys)
398 1.2 cgd return (1);
399 1.2 cgd /* check if crossing a DMA page boundary */
400 1.2 cgd if (((u_int)priorpage ^ (u_int)phys) & dma_pgmsk)
401 1.2 cgd return (1);
402 1.2 cgd }
403 1.1 cgd priorpage = phys;
404 1.1 cgd }
405 1.1 cgd return (0);
406 1.1 cgd }
407 1.1 cgd
408 1.1 cgd /* head of queue waiting for physmem to become available */
409 1.1 cgd struct buf isa_physmemq;
410 1.1 cgd
411 1.1 cgd /* blocked waiting for resource to become free for exclusive use */
412 1.1 cgd static isaphysmemflag;
413 1.1 cgd /* if waited for and call requested when free (B_CALL) */
414 1.1 cgd static void (*isaphysmemunblock)(); /* needs to be a list */
415 1.1 cgd
416 1.1 cgd /*
417 1.1 cgd * Allocate contiguous physical memory for transfer, returning
418 1.1 cgd * a *virtual* address to region. May block waiting for resource.
419 1.1 cgd * (assumed to be called at splbio())
420 1.1 cgd */
421 1.1 cgd caddr_t
422 1.1 cgd isa_allocphysmem(caddr_t va, unsigned length, void (*func)()) {
423 1.1 cgd
424 1.1 cgd isaphysmemunblock = func;
425 1.1 cgd while (isaphysmemflag & B_BUSY) {
426 1.1 cgd isaphysmemflag |= B_WANTED;
427 1.1 cgd sleep(&isaphysmemflag, PRIBIO);
428 1.1 cgd }
429 1.1 cgd isaphysmemflag |= B_BUSY;
430 1.1 cgd
431 1.1 cgd return((caddr_t)isaphysmem);
432 1.1 cgd }
433 1.1 cgd
434 1.1 cgd /*
435 1.1 cgd * Free contiguous physical memory used for transfer.
436 1.1 cgd * (assumed to be called at splbio())
437 1.1 cgd */
438 1.1 cgd void
439 1.1 cgd isa_freephysmem(caddr_t va, unsigned length) {
440 1.1 cgd
441 1.1 cgd isaphysmemflag &= ~B_BUSY;
442 1.1 cgd if (isaphysmemflag & B_WANTED) {
443 1.1 cgd isaphysmemflag &= B_WANTED;
444 1.1 cgd wakeup(&isaphysmemflag);
445 1.1 cgd if (isaphysmemunblock)
446 1.1 cgd (*isaphysmemunblock)();
447 1.1 cgd }
448 1.1 cgd }
449 1.1 cgd
450 1.1 cgd /*
451 1.1 cgd * Handle a NMI, possibly a machine check.
452 1.1 cgd * return true to panic system, false to ignore.
453 1.1 cgd */
454 1.1 cgd isa_nmi(cd) {
455 1.1 cgd
456 1.1 cgd log(LOG_CRIT, "\nNMI port 61 %x, port 70 %x\n", inb(0x61), inb(0x70));
457 1.1 cgd return(0);
458 1.1 cgd }
459 1.1 cgd
460 1.1 cgd /*
461 1.1 cgd * Caught a stray interrupt, notify
462 1.1 cgd */
463 1.1 cgd isa_strayintr(d) {
464 1.1 cgd
465 1.1 cgd /* DON'T BOTHER FOR NOW! */
466 1.1 cgd /* for some reason, we get bursts of intr #7, even if not enabled! */
467 1.4 cgd /*
468 1.4 cgd * Well the reason you got bursts of intr #7 is because someone
469 1.4 cgd * raised an interrupt line and dropped it before the 8259 could
470 1.4 cgd * prioritize it. This is documented in the intel data book. This
471 1.4 cgd * means you have BAD hardware! I have changed this so that only
472 1.4 cgd * the first 10 get logged, then it quits logging them, and puts
473 1.4 cgd * out a special message. rgrimes 3/25/1993
474 1.4 cgd */
475 1.4 cgd extern u_long isa_stray_intrcnt;
476 1.4 cgd
477 1.4 cgd isa_stray_intrcnt++;
478 1.4 cgd if (isa_stray_intrcnt <= 10)
479 1.4 cgd log(LOG_ERR,"ISA strayintr %x\n", d);
480 1.4 cgd if (isa_stray_intrcnt == 10)
481 1.4 cgd log(LOG_CRIT,"Too many ISA strayintr not logging any more\n");
482 1.1 cgd }
483 1.1 cgd
484 1.1 cgd /*
485 1.1 cgd * Wait "n" microseconds. Relies on timer 0 to have 1Mhz clock, regardless
486 1.1 cgd * of processor board speed. Note: timer had better have been programmed
487 1.1 cgd * before this is first used!
488 1.1 cgd */
489 1.1 cgd DELAY(n) {
490 1.1 cgd int tick = getit(0,0) & 1;
491 1.1 cgd
492 1.1 cgd while (n--) {
493 1.1 cgd /* wait approximately 1 micro second */
494 1.1 cgd while (tick == getit(0,0) & 1) ;
495 1.1 cgd
496 1.1 cgd tick = getit(0,0) & 1;
497 1.1 cgd }
498 1.1 cgd }
499 1.1 cgd
500 1.1 cgd getit(unit, timer) {
501 1.1 cgd int port = (unit ? IO_TIMER2 : IO_TIMER1) + timer, val;
502 1.1 cgd
503 1.1 cgd val = inb(port);
504 1.1 cgd val = (inb(port) << 8) + val;
505 1.1 cgd return (val);
506 1.1 cgd }
507 1.1 cgd
508 1.1 cgd extern int hz;
509 1.1 cgd
510 1.1 cgd static beeping;
511 1.1 cgd static
512 1.1 cgd sysbeepstop(f)
513 1.1 cgd {
514 1.1 cgd /* disable counter 2 */
515 1.1 cgd outb(0x61, inb(0x61) & 0xFC);
516 1.1 cgd if (f)
517 1.1 cgd timeout(sysbeepstop, 0, f);
518 1.1 cgd else
519 1.1 cgd beeping = 0;
520 1.1 cgd }
521 1.1 cgd
522 1.1 cgd void sysbeep(int pitch, int period)
523 1.1 cgd {
524 1.1 cgd
525 1.1 cgd outb(0x61, inb(0x61) | 3); /* enable counter 2 */
526 1.1 cgd outb(0x43, 0xb6); /* set command for counter 2, 2 byte write */
527 1.1 cgd
528 1.1 cgd outb(0x42, pitch);
529 1.1 cgd outb(0x42, (pitch>>8));
530 1.1 cgd
531 1.1 cgd if (!beeping) {
532 1.1 cgd beeping = period;
533 1.1 cgd timeout(sysbeepstop, period/2, period);
534 1.1 cgd }
535 1.1 cgd }
536 1.1 cgd
537 1.1 cgd /*
538 1.1 cgd * Pass command to keyboard controller (8042)
539 1.1 cgd */
540 1.1 cgd unsigned kbc_8042cmd(val) {
541 1.1 cgd
542 1.1 cgd while (inb(KBSTATP)&KBS_IBF);
543 1.1 cgd if (val) outb(KBCMDP, val);
544 1.1 cgd while (inb(KBSTATP)&KBS_IBF);
545 1.1 cgd return (inb(KBDATAP));
546 1.1 cgd }
547